What I want to crawl is the user_name and content in the outermost tag of this p. There are many, many tags in the middle. I just crawled down all the tags in this p. I want to know how to keep the outermost tag that I need
r = requests.get("http://tieba.baidu.com/p/2108034524?pn=4")
soup = BeautifulSoup(r.content, "lxml")
users = soup.find_all("p", class_="l_post")
for user in users:
print(user["data-field"])
# 其他处理
What I want to crawl is the user_name and content in the outermost tag of this p. There are many, many tags in the middle. I just crawled down all the tags in this p. I want to know how to keep the outermost tag that I need
Then process the extracted content