爬取豆瓣Top250
import requestsimport bs4
res = requests.get("https://movie.douban.com/top250")
soup = bs4.BeautifulSoup(res.text,"html.parser")
targets = soup.find_all("div", class_="hd")
with open("豆瓣电影.txt",'w') as f:
for each in targets:
f.write(each.a.span.text)
为什么啥也没爬到啊 本帖最后由 isdkz 于 2022-4-12 17:23 编辑
现在豆瓣不加点反爬是爬不出的import requests
import bs4
res = requests.get("https://movie.douban.com/top250", headers={'User-Agent':'Mozilla/5.0'}) # 加个反爬
soup = bs4.BeautifulSoup(res.text,"html.parser")
targets = soup.find_all("div", class_="hd")
with open("豆瓣电影.txt",'w') as f:
for each in targets:
f.write(each.a.span.text)
{:5_109:} {:10_257:} {:5_95:} isdkz 发表于 2022-4-12 17:11
现在豆瓣不加点反爬是爬不出的
谢谢 66666666666666666666666666 {:10_256:} 1050293757 发表于 2022-4-12 20:35
{:10_256:} {:7_146:} {:10_275:} {:5_109:} 加油 {:10_256:} 学习
加油 {:5_109:} {:10_257:} {:10_256:}{:10_256:}{:10_256:} {:10_277:}
页:
[1]
2