最近有爬虫相关的需求,所以上B站找了个视频(链接在文末)看了一下,做了一个小程序出来,大体上没有修改,只是在最后的存储上,由txt换成了excel。
- 简要需求:爬虫爬取 猫眼电影TOP100榜单 数据
- 使用语言:python
- 工具:PyCharm
- 涉及库:requests、re、openpyxl(高版本excel操作库)
实现代码
1 # -*- coding: utf-8 -*- 2 # @Author : yocichen 3 # @Email : yocichen@126.com 4 # @File : MaoyanTop100.py 5 # @Software: PyCharm 6 # @Time : 2019/11/6 9:52 7 8 import requests 9 from requests import RequestException 10 import re 11 import openpyxl 12 13 # Get page's html by requests module 14 def get_one_page(url): 15 try: 16 headers = { 17 'user-agent':