当前位置:网站首页>爬虫练习题(二)
爬虫练习题(二)
2022-07-05 19:05:00 【InfoQ】
"""
目标网站:https://www.1ppt.com/moban/
爬取要求:
1、 翻页爬取这个网页上面的源代码
2、 并且保存到本地,注意编码
"""
'''
1.分析网站:
https://www.1ppt.com/moban/ 第一页
https://www.1ppt.com/moban/ppt_moban_2.html 第二页
https://www.1ppt.com/moban/ppt_moban_3.html 第三页
'''
import urllib.request
start = int(input("输入起始页")) # 转int
end = int(input("输入结束页"))
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'
}
for n in range(start, end + 1):
url = 'https://www.1ppt.com/moban/ppt_moban_{}.html'.format(n)
print(url)
req = urllib.request.Request(url, headers=headers) # 实例化请求对象
response = urllib.request.urlopen(req) # 发送请求的方法
with open(f'第{n}页.html', 'a', encoding='gb2312') as f:
f.write(response.read().decode('gb2312'))
边栏推荐
- word如何转换成pdf?word转pdf简单的方法分享!
- Postman核心功能解析 —— 参数化和测试报告
- 公司破产后,黑石们来了
- Pandora IOT development board learning (HAL Library) - Experiment 8 timer interrupt experiment (learning notes)
- XML basic knowledge concept
- HAC cluster modifying administrator user password
- Ultrasonic ranging based on FPGA
- Oracle故障处理:Ora-10873:file * needs to be either taken out of backup or media recovered
- Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法
- Vagrant2.2.6 supports virtualbox6.1
猜你喜欢
JAD的安装、配置及集成IDEA
【AI 框架基础技术】自动求导机制 (Autograd)
14、用户、组和权限(14)
PHP uses ueditor to upload pictures and add watermarks
Fuzor 2020軟件安裝包下載及安裝教程
关于 Notion-Like 工具的反思和畅想
100million single men and women supported an IPO with a valuation of 13billion
CF: B. almost Ternary Matrix [symétrie + règles de recherche + Construction + I am Construction Waste]
Oracle Chinese sorting Oracle Chinese field sorting
Tianyi cloud understands enterprise level data security in this way
随机推荐
Apprentissage du projet MMO I: préchauffage
泰山OFFICE技术讲座:由行的布局高度,谈绘制高度的高度溢出、高度缩水(全网首发)
公司破产后,黑石们来了
Fuzor 2020软件安装包下载及安装教程
The era of Web3.0 is coming. See how Tianyi cloud storage resources revitalize the system to enable new infrastructure (Part 2)
Debezium系列之:解析默认值字符集
自动化测试的好处
面试官:Redis中集合数据类型的内部实现方式是什么?
IFD-x 微型红外成像仪(模块)关于温度测量和成像精度的关系
Get wechat avatar and nickname with uniapp
块编辑器如何选择?印象笔记 Verse、Notion、FlowUs
Why can't Bi software do correlation analysis? Take you to analyze
Hiengine: comparable to the local cloud native memory database engine
Blue sky drawing bed Apple quick instructions
毫米波雷达人体感应器,智能感知静止存在,人体存在检测应用
MySQL中字段类型为longtext的值导出后显示二进制串方式
Go语言学习教程(十五)
5. Data access - entityframework integration
android中常见的面试题,2022金九银十Android大厂面试题来袭
国海证券在网上开户安全吗?