python爬虫---豆瓣Top250电影采集

代码:文章来源地址https://www.yii666.com/article/754189.html文章地址https://www.yii666.com/article/754189.html网址:yii666.com<网址:yii666.com文章来源地址:https://www.yii666.com/article/754189.html

import requests
from bs4 import BeautifulSoup as bs
import time def get_movie(url):
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
} resp = requests.get(url, headers=headers).text
soup = bs(resp, "html.parser") items = soup.find_all("div", class_="hd") for i in items:
tag = i.find("a")
link = tag["href"]
name = tag.find(class_="title").text
print("电影名称:%s,电影地址:%s" % (name, link)) url = "https://movie.douban.com/top250?start={}"
urls = [url.format(num * 25) for num in range(10)]
for link in urls:
get_movie(link)
time.sleep(1)

版权声明:本文内容来源于网络,版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。文本页已经标记具体来源原文地址,请点击原文查看来源网址,站内文章以及资源内容站长不承诺其正确性,如侵犯了您的权益,请联系站长如有侵权请联系站长,将立刻删除

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信图片_20190322181744_03.jpg

微信扫一扫打赏

请作者喝杯咖啡吧~

支付宝扫一扫领取红包,优惠每天领

二维码1

zhifubaohongbao.png

二维码2

zhifubaohongbao2.png