python 爬虫软件第一个程序

19.爬虫

爬虫,又叫做网络爬虫,按照一定的规律,去抓取万维网上的信息的一个程序
爬虫的目的:采集数据
爬虫的分类:
通用的网络爬虫(检索引擎(百度))遵循robots协议
聚焦网络爬虫
增量式网络爬虫
累计式爬虫
深层网络爬虫(暗网)

19.1爬虫的第一个程序

#导包 网络库
 import urllib.request 
 url = "http://www.sina.com.cn" 
 #响应头 
 response = urllib.request.urlopen(url) 
 #获取数据 
 data = response.read() 
 print(data)
#导包 网络库 
import urllib.request 
url = "http://www.sina.com.cn"
 #响应头 
 response = urllib.request.urlopen(url) 
 #获取数据 
 data = response.read() 
# print(data)
 with open("sina.html","wb") as f: 
 f.write(data) 
 print("新浪信息采集完毕")
#导包 网络库 
import urllib.request 
url = "http://www.sina.com.cn" 
#响应头 
response = urllib.request.urlopen(url)
 #获取数据 
 data = response.read()
  # print(data)
   html = data.decode("utf-8") 
   with open("sina1.html","w",encoding="utf-8") as f: 
   f.write(html) 
   print("新浪信息采集完毕")

19.2 fidder的使用

抓包工具
fidder
python 爬虫软件第一个程序_第1张图片
选择:I Agree
python 爬虫软件第一个程序_第2张图片
选择安装的路径
python 爬虫软件第一个程序_第3张图片
选择install 进行安装
python 爬虫软件第一个程序_第4张图片
点击close,安装完后
打开软件,打开浏览器,百度页面,会出现很多请求
python 爬虫软件第一个程序_第5张图片
remove all 清除
python 爬虫软件第一个程序_第6张图片
打开pycharm运行代码
然后到fiddler中看到如下:
python 爬虫软件第一个程序_第7张图片
Accept-Encoding: identity 期望编码
User-Agent: Python-urllib/3.9 用户代理对象
Connection: close
Host: www.sina.com.cn
网页百度页面:查看源代码
python 爬虫软件第一个程序_第8张图片
python 爬虫软件第一个程序_第9张图片
python 爬虫软件第一个程序_第10张图片
这是goolge提供的抓包工具,只能抓网页,不能抓pycharm,所以用fiddler
百度就是通过User-Agent来判断是客户端还是PC端
python 爬虫软件第一个程序_第11张图片
python 爬虫软件第一个程序_第12张图片

你可能感兴趣的:(python,爬虫,fiddler)