python爬虫 豆瓣影评的爬取cookies实现自动登录账号
频繁的登录网页会让豆瓣锁定你的账号……
网页请求
使用cookies来实现的自动登录账号,这里的cookies因为涉及到账号我屏蔽了,具体的cookies获取方法直接可以让浏览器实现自动登录后,在网页请求信息中自己找到。
def askURL(url):
head = {
"User-Agent": "Mozilla / 5.0(Windows NT 10.0;WOW64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 77.0.3865.90Safari / 537.36"
}
cookies ={
"Cookie":' ***********************'
}
# request = urllib.request.Request(url, headers=head)
# html = ""
# response = urllib.request.urlopen(request)
# html = response.read().decode("utf-8")
html = requests.get(url,cookies=cookies,headers=head)
print("网站返回成功")
return html.text
获取数据代码片段
再看豆瓣影评的时候,我发现他的所有评论我没有办法完全获取下来
他这里的评论我没理解错的话应该