|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import requests
- import 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)
-
复制代码
|
|