Python数据分析
2021/9/3 17:06:06
本文主要是介绍Python数据分析,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
- 爬取部分豆瓣top250
1 import requests 2 from lxml import etree 3 4 5 def getData(number): 6 url = "https://movie.douban.com/top250?start={0}".format(number) 7 headers = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko'} 8 response = requests.get(url, timeout=10, headers=headers) 9 response.encoding = 'utf-8' 10 parser = etree.HTMLParser(encoding='utf-8') 11 html = etree.HTML(response.text, parser=parser) 12 message = html.xpath('//ol[@class="grid_view"]/li/div[@class="item"]/div[@class="pic"]/a/img/@alt') # 根据网页结构不同,自行调整 13 print(message) 14 15 16 if __name__ == '__main__': 17 # 每页25个电影,取前10页 18 for number in range(0, 250, 25): 19 getData(number)
这篇关于Python数据分析的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-26Python基础编程
- 2024-11-25Python编程基础:变量与类型
- 2024-11-25Python编程基础与实践
- 2024-11-24Python编程基础详解
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南