我想获取我的网站https://lifesciences.cactusglobal.com/的特定javascript和css网络请求的状态。这些网络请求可以在chrome网络中看到。我想打印请求url及其响应代码。下面附上的屏幕截图仅供参考,请检查带下划线的请求:
我尝试使用包selenium-wire
driver.get('https://www.google.com')
for request in driver.requests:
if request.response:
print(
request.url,
request.response.status_code,
request.response.headers['Content-Type']
)
但它只返回输入的url的响应和标题,而不返回网络请求。在selenium python中,还有其他方法可以遍历网络请求吗?
谢谢
非常感谢你的支持。我找到了一个非常符合我要求的解决方案。
参考这些链接:
https://gist.github.com/rengler33/f8b9d3f26a518c08a414f6f86109863chttps://www.rkengler.com/how-to-capture-network-traffic-when-scraping-with-selenium-and-python/
还发现一个包是一个简单的解决方法(但不要坚持)-
pip install selenium-wire
输出很混乱,但是尝试像这样获取网络请求,它似乎对我有用:
相关问题 更多 >
编程相关推荐