爬虫问题
百度贴吧如何用re爬取楼主及回复的用户?帮帮我吧,谢谢大佬们了 来个具体链接~ <div id="post_content_\d+?" class="d_post_content j_d_post_content " style="display:;">(.+?)</div>
这样正则试试? Twilight6 发表于 2020-7-7 20:47
来个具体链接~
https://tieba.baidu.com/p/6503175911 pyrhon萌新# 发表于 2020-7-8 16:24
https://tieba.baidu.com/p/6503175911
抱歉,之前没看到评论,这样可以吧?
import requests
import re
url = 'https://tieba.baidu.com/p/6503175911'
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'
}
request = requests.get(url,headers=headers)
html = request.text
contents = re.findall(r'.+style="display:;">(.+?)</div>',html)
for i in range(len(contents)):
contents = contents.strip()
print(contents)
页:
[1]