import pcap  # 安装的是pypcap,本博客有安装方法,不过也比较乱,试试吧。
import dpkt
import socket
import datetime def sniffer(str):
pc = pcap.pcap()
for timestamp, buf in pc:
eth = dpkt.ethernet.Ethernet(buf)
if not isinstance(eth.data, dpkt.ip.IP):
print('Non IP Packet type not supported %s\n' % eth.data.__class__.__name__)
continue
ip = eth.data
if isinstance(ip.data, dpkt.tcp.TCP):
tcp = ip.data
try:
request = dpkt.http.Request(tcp.data)
except (dpkt.dpkt.NeedData, dpkt.dpkt.UnpackError):
continue
print('HTTP request: %s\n' % repr(request))
if request.headers['host'] == str: # 自行替换需要抓的网站。
print(request)
# print('type:', type(request))
host = request.headers['host']
connection = request.headers['connection']
accept = request.headers['accept']
user_agent = request.headers['user-agent']
accept_encoding = request.headers['accept-encoding']
accept_language = request.headers['accept-language']
cookie = request.headers['cookie']
return request
break request = sniffer('www.******.net')
print('---------')
print(request.headers['host'])

这个代码是抓取一个网站请求的request信息。

python 抓取request信息,各种cookie,user-agent类的信息,只调试到http可以抓取,https貌似不行。的更多相关文章

  1. Python爬虫教程-12-爬虫使用cookie爬取登录后的页面(人人网)(上)

    Python爬虫教程-12-爬虫使用cookie(上) 爬虫关于cookie和session,由于http协议无记忆性,比如说登录淘宝网站的浏览记录,下次打开是不能直接记忆下来的,后来就有了cooki ...

  2. Python爬虫之requests+正则表达式抓取猫眼电影top100以及瓜子二手网二手车信息(四)

    requests+正则表达式抓取猫眼电影top100 一.首先我们先分析下网页结构 可以看到第一页的URL和第二页的URL的区别在于offset的值,第一页为0,第二页为10,以此类推. 二.< ...

  3. Python爬虫教程-13-爬虫使用cookie爬取登录后的页面(人人网)(下)

    Python爬虫教程-13-爬虫使用cookie爬取登录后的页面(下) 自动使用cookie的方法,告别手动拷贝cookie http模块包含一些关于cookie的模块,通过他们我们可以自动的使用co ...

  4. 带参数,头信息,代理,cookie爬取

    1.get传参 (1)汉字报错 :解释器器ascii没有汉字 url汉字转码 urllib.parse.quote safe="string.printtable" (2)字典传参 ...

  5. 拉勾网爬取全国python职位并数据分析薪资,工作经验,学历等信息

    首先前往拉勾网“爬虫”职位相关页面 确定网页的加载方式是JavaScript加载 通过谷歌浏览器开发者工具分析和寻找网页的真实请求,确定真实数据在position.Ajax开头的链接里,请求方式是PO ...

  6. 利用cookie存放模糊查询的信息

    将前台传入后台的查询条件,存放到cookie中,并加入响应对象中,将该查询条件存放入浏览器端.(会话cookie,存放在浏览器的内存中,浏览器关闭,cookie消失.[不设置路径,和生命周期]) 注意 ...

  7. Symfony 2.0 认识Request, Response, Session, Cookie

    在上一节中,我们提到了如何创建一个Bunlde 并且在默认控制器中添加一些方法.如果有参照之前的说法进行的话,读者很有可能会被提示说 返回的Response对象不能为空.好啦,我们就来研究一下,怎么从 ...

  8. python爬虫之request and BeautifulSoup

    1.爬虫的本质是什么? 模仿浏览器的行为,爬取网页信息. 2.requests 1.get请求 无参数实例 import requests ret = requests.get('https://gi ...

  9. 【爬虫问题】爬取tv.sohu.com的页面, 提取视频相关信息

    尝试解决下面的问题 问题: 爬取tv.sohu.com的页面, 提取视频相关信息,不可用爬虫框架完成 何为视频i关信息?属性有哪些? 需求: 做到最大可能的页面覆盖率 *使用httpClient 模拟 ...

随机推荐

  1. Python3基础 str partition 以参数字符串切分字符串,只切分为三部分

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  2. JavaScript:Object属性方法

    Object的属性(firebug中没有找到) var pro={ city:"shanghai", list:[,,,,] } var Person=function(name, ...

  3. C#学习笔记(十五):抽象方法、抽象类、多态和接口

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. 【TCP/IP详解 卷一:协议】第十九章 TCP的交互数据流

    19.1 引言 前一章我们介绍了TCP连接的建立与释放:三握四挥,以及状态转移图. TCP报文段分为:交互数据,以及成块数据(下一章介绍). 交互数据:例如telnet,ssh,这种类型的协议在大多数 ...

  5. 【Coursera】Fourth Week(2)

    Netscape JavaScript and Firefox 当Microsoft收购Netscape失败之后: JavaScript 创造并用于与 Visual Basic 竞争(1995). N ...

  6. mybatis 关于传long 类型问题

    @Datapublic class PrealertPackageStatusDTO { private Integer nowStatus; /** * packageStatusEnum */ p ...

  7. Linux——文件搜索命令简单笔记

    一: 命令名称:which 命令所在路径:/usr/bin/which 执行权限:所有用户 功能描述:显示系统命令所在目录 范例:$ which ls 还有一个whereeis ls 命令 二: 命令 ...

  8. 查看 rospkg 变量

    echo $ROS_PACKAGE_PATH

  9. [原][osg][osgEarth]关于在OE中使用物理引擎的调研

    关于物理引擎旋转的一些整理 参考文档 http://blog.wolfire.com/2010/03/Comparing-ODE-and-Bullet 介绍ODE和bullet的利弊 http://s ...

  10. node 工程化 web项目

    1.结构 node_modules   ( ... ) routers     ( main.js  ) views    ( index.html   about.HTML  404.html ) ...