ChatGPT提示词
提供一个爬虫代码,在豆瓣网上找到满江红的影评中5分好评的评论,并进行点赞操作
ChatGPT回复
import requests
from bs4 import BeautifulSoup# 设置请求头,模拟浏览器访问
headers = {
“User-Agent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36”,
“Referer”: “https://movie.douban.com/”
}# 发起请求获取影评页面
url = “https://movie.douban.com/subject/1309060/reviews?rating=5”
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, “html.parser”)# 解析页面获取评论列表
reviews = soup.find_all(“div”, class_=”main review-item”)
for review in reviews:
# 获取评论的点赞链接
like_link = review.find(“a”, class_=”j a_show_login like ” + “like-” + review[“id”])
if like_link:
# 发起点赞请求
like_url = “https://movie.douban.com/j/review/” + review[“id”] + “/like”
requests.post(like_url, headers=headers)
print(“点赞成功:”, review.text.strip())