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
 
 选择:I Agree
 
 选择安装的路径
 
 选择install 进行安装
 
 点击close,安装完后
 打开软件,打开浏览器,百度页面,会出现很多请求
 
 remove all 清除
 
 打开pycharm运行代码
 然后到fiddler中看到如下:
 
 Accept-Encoding: identity 期望编码
 User-Agent: Python-urllib/3.9 用户代理对象
 Connection: close
 Host: www.sina.com.cn
 网页百度页面:查看源代码
 
 
 
 这是goolge提供的抓包工具,只能抓网页,不能抓pycharm,所以用fiddler
 百度就是通过User-Agent来判断是客户端还是PC端
 
 
转载:https://blog.csdn.net/balanceone/article/details/115913172
查看评论
					