爬取豆瓣电影Top250

徘徊边缘 提交于 2019-11-29 23:56:08
import requests
from lxml import etree
# 获取豆瓣电影排行前250的电影信息
count = 0
for page in range(0,10):
    url = 'https://movie.douban.com/top250?start=%s&filter='%(page*25)
    response = requests.get(url)
    root = etree.HTML(response.content)
    big_cate_list = root.xpath("//ol[@class='grid_view']/li")
    #  标签的 href 属性用于指定超链接目标的 URL
    for big_cate in big_cate_list:
        count = count + 1
        # big_cate_href = big_cate.xpath("div/div/a/@href")[0]
        big_cate_alt = big_cate.xpath("div/div/a/img/@alt")[0]
        big_cate_src = big_cate.xpath("div/div/a/img/@src")[0]
        big_cate_intro = big_cate.xpath("div/div[@class='info']/div[@class='bd']/p/text()")[0]
        big_cate_intro1 = big_cate.xpath("div/div[@class='info']/div[@class='bd']/p/text()")[1]
        #new_intro = "--".join(big_cate_intro)
        big_cate_quote = big_cate.xpath("div/div[@class='info']/div[@class='bd']/p[@class='quote']/span/text()")[0]
        print(count, big_cate_alt, big_cate_src, big_cate_intro, big_cate_intro1,big_cate_quote)
    # 网站首页https://movie.douban.com/top250?start=0&filter=
    # 网站第二页 https://movie.douban.com/top250?start=25&filter=
    # 网站第三页 https://movie.douban.com/top250?start=50&filter=
    # 网站第10页 https://movie.douban.com/top250?start=225&filter=

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!