python使用XPATH爬取电影票房

爬取电影票房前50(网票)

在这里插入图片描述

# coding:utf-8
# 获取电影票房排行榜前五十
__Author__ = 'Negoo_wen'
import requests
from lxml import etree

url = 'http://58921.com/alltime/wangpiao'
def main():
    html = requests.get(url).content
    tree = etree.HTML(html)
    box = tree.xpath('//*[@class="odd" or @class="even"]/td[2]/a/text()')
    for i in range(len(box)):
        print str(i+1)+" :  " + box[i]

if __name__ == '__main__':
    main()

所有代码脚本在:https://github.com/SaltNego/Web_Crawler_Notes

发布了61 篇原创文章 · 获赞 22 · 访问量 4236

猜你喜欢

转载自blog.csdn.net/yiqiushi4748/article/details/104036765