#爬取豆瓣短评
import requests
import re
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3676.400 QQBrowser/10.5.3738.400'}
url = 'https://book.douban.com/subject/1084336/comments/'
r = requests.get(url=url,headers = headers).text
pattern = '<span class="short">(.*?)</span>'
result = re.findall(pattern,r)
print(result)
re正则表示式爬取网页
最新推荐文章于 2022-05-29 11:41:10 发布