安装
pip install selenium-wire
使用
from seleniumwire import webdriver
driver=webdriver.Chrome()
driver.get("https://baidu.com")
driver.requests
from seleniumwire.utils import decode
body = decode(response.body, response.headers.get('Content-Encoding', 'identity'))
增加代理
seleniumwire_options = {
"proxy": {
"http": "http://127.0.0.1:7890",
"https": "http://127.0.0.1:7890",
"no_proxy": "http://127.0.0.1:7890",
}
}
driver = webdriver.Chrome(seleniumwire_options=seleniumwire_options)
等待某个请求
request = driver.wait_for_request('/v2/api/dapps')
请求属性
- method: HTTP 请求方法类型,例如:GET,POST
- url: 请求URL地址
- path: 请求路径
- querystring: 请求URL参数, 例如:foo=bar
- params: 请求参数作为字典返回
- headers: 请求头信息作为字典返回
- body: 请求内容以字节返回
- response: 该请求对应的响应对象
响应属性(通过requests对象的response属性获取)
- status_code: 响应状态码
- reason: 响应结果, 例如:OK 或Not Found
- headers: 响应头信息作为字典返回
- body: 响应体内容以字节返回