首页 > 其他 > 详细

第十二节 豆瓣电影实战

时间:2020-03-16 22:16:04      阅读:69      评论:0      收藏:0      [点我收藏+]
import requests
from lxml import etree


headers = {
    User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36,
    Referer:https://pagead2.googlesyndication.com/pagead/s/cookie_push.html
}
url = https://movie.douban.com/cinema/nowplaying/fuzhou/
resp = requests.get(url, headers = headers)
text = resp.text
html = etree.HTML(text)
ul = html.xpath(//ul[@class="lists"])[0]
lis = ul.xpath(./li[@class="list-item"])
movies = []
for li in lis:
    title = li.xpath(@data-title)
    score = li.xpath(@data-score)
    star = li.xpath(@data-star)
    duration = li.xpath(@data-duration)
    region = li.xpath(@data-region)
    director = li.xpath(@data-director)
    actors = li.xpath(@data-actors)
    movie = {
        "title":title,
        "score":score,
        "star":star,
        "duration":duration,
        "region":region,
        "director":director,
        "actors":actors
    }
    movies.append(movie)
for m in movies:
    print(m)

 

第十二节 豆瓣电影实战

原文:https://www.cnblogs.com/kogmaw/p/12506966.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!