当前位置:网站首页>【selenium自动化过程中的api抓包】browsermobproxy的安装和配置
【selenium自动化过程中的api抓包】browsermobproxy的安装和配置
2022-06-28 21:42:00 【白速龙王的回眸】
第一步
pip install browsermob-proxy
先装一个包
第二步
要求jdk1.8以上的环境变量依赖
ps:如果是刚配的环境记得,重启一下
第三步
下载java端BrowserMob-Proxy包:http://bmp.lightbody.net/
直接拿来主义(在py配置的时候要记得写上browsermob-proxy.bat地址)
实验:百度一下

比如说,我想随便抓一个js的response看看

确实可以看到一些粗略的内容,细致的js代码还需要探索一下
完整代码
from browsermobproxy import Server
from selenium import webdriver
import time
import pprint
class ProxyManger:
__BMP = r"C:\Users\Irving\Desktop\echain\browsermob-proxy-2.1.4-bin\browsermob-proxy-2.1.4\bin\browsermob-proxy.bat"
def __init__(self):
self.__server = Server(ProxyManger.__BMP)
self.__client = None
def start_server(self):
self.__server.start()
return self.__server
def start_client(self):
self.__client = self.__server.create_proxy(params={
"trustAllServers": "true"})
return self.__client
@property
def client(self):
return self.__client
@property
def server(self):
return self.__server
if __name__=="__main__":
# 开启Proxy
proxy = ProxyManger()
server = proxy.start_server()
client = proxy.start_client()
# 配置Proxy启动WebDriver
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server={}".format(client.proxy))
options.add_argument('--ignore-certificate-errors')
options.add_argument('--headless')
#chromePath = r"D:\AzRjN\anaconda3_7\envs\demo36\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe"
driver = webdriver.Chrome(chrome_options=options)
# 获取返回的内容
client.new_har("baidu.com", options={
'captureHeaders': True, 'captureContent': True})
driver.get("https://www.baidu.com/")
time.sleep(3)
result = client.har
print(result)
for entry in result['log']['entries']:
_url = entry['request']['url']
print("请求地址:", _url)
if "https://pss.bdstatic.com/r/www/cache/static/protocol/https/amd_modules/san/dist/san_5017f11.js" in _url:
_response = entry['response']
_content = _response['content']
print("---------https://pss.bdstatic.com/r/www/cache/static/protocol/https/amd_modules/san/dist/san_5017f11.js 请求响应内容:", _response)
server.stop()
总结
selenium一边自动化操作
browsermobproxy一边抓包
边栏推荐
- Rule engine development experience sharing - reddit
- The rogue downloader named by 315 is back
- 职场小技巧 | 了解岗位优势三板斧之“识人”
- PAT 1021. Traversal of the deep root (25 points) graph, DFS, calculating the number of connected components
- Is it safe to open an account on great wisdom
- Microsoft's exclusive payment function has also been perfectly unlocked
- Webrtc audio and video development - experience
- Alist+raidrive gives the computer a complete 8billion GB hard disk drive
- PHP uses stack to solve maze problem
- QT 一个控件的坐标怎么相对固定显示在另一个控件上(坐标系)
猜你喜欢

17 `bs对象.节点名h3.parent` parents 获取父节点 祖先节点

Postman introduction and installation steps

Biovendor free light chain( κ and λ) Test steps of ELISA Kit

Rosdep update using fishros to solve ros1/ros2 problems 2022
![Sword finger offer:[day 2 linked list (simple)] --- > print the linked list from end to end](/img/d6/824985b74b27a1bee456c2cebbac26.jpg)
Sword finger offer:[day 2 linked list (simple)] --- > print the linked list from end to end

Study on bifunctional crosslinker lumiprobe sulfoacyanine 7 dicarboxylic acid

AI deep dive of Huawei cloud

Multinomial distribution (a discrete distribution)

【激活函数】

10、标准I/O输入输出重定向及管道
随机推荐
杆会睡不着觉
Sword finger offer:[day 2 linked list (simple)] --- > reverse linked list
10、标准I/O输入输出重定向及管道
QStringLiteral(str)
小样本利器2.文本对抗+半监督 FGSM & VAT & FGM代码实现
PHP自学Go日记(四):GO的变量声明方式
How to make up the PMP Exam? How much is the make-up exam?
Safety innovation practice | Haitai Fangyuan was invited to participate in the technical exchange Seminar on "network information innovation and value co creation in the digital age"
be careful! The PMP emergency postponement exam is due today!
#yyds干货盘点# 解决剑指offer: 连续子数组的最大和(二)
Leetcode: merge two ordered linked lists_ twenty-one
开通股票炒股账号安全吗?是靠谱的吗?
How do independent site sellers efficiently manage complex Facebook pages?
零基础自学SQL课程 | SQL中的日期函数大全
LeetCode:合并K个升序链表_23
Rust language survey results in 2021
PE file-
Lumiprobe proteorange protein gel dye instructions
LeetCode123. The best time to buy and sell stocks III
IPv6 comprehensive experiment