python - 如何从 Python 中的网络选项卡中读取?
问题描述
使用 Selenium、Requests 和 Beautiful Soup,我希望能够找到并打印此 .m3u8 链接(或此处显示的任何链接),但我不知道在 Python 中显示请求。
def locator(url):
driver = sp.driver # just geckodriver with profile
driver.get(url)
sleep(4)
# from here needs to somehow access the network tab & locate GET requests with Host == "cfvod.kaltura.com"
解决方案
不得不使用 ChromeDriver、PyChrome 和 DevTools 协议,但这有效:
def outputstart(**kwargs):
print("START ", kwargs)
driver = sp.driver # my chromedriver profile with an argument added for port 8000
dev_tools = pychrome.Browser(url="http://localhost:8000")
tab = dev_tools.list_tab()[0]
tab.start()
url = 'https://google.com'
start = time.time()
driver.get(url)
tab.call_method("Network.emulateNetworkConditions",
offline=False,
latency=100,
downloadThroughput=93750,
uploadThroughput=31250,
connectionType="wifi")
def outputstart(**kwargs):
print("START ", kwargs)
tab.call_method("Network.enable", _timeout=20)
tab.set_listener("Network.requestWillBeSent", outputstart)
推荐阅读
- java - 如何在无网络模式下将自定义命令行传递给 locust
- .net - 使用 codefirst 连接并创建数据库,错误 26
- rest - OWASP 保护 restapi 免受点击劫持的安全指南,它们准确吗?
- javascript - 如何解决 JavaScript 中的堆栈问题?
- kotlin - 智能投不投String?!value.isNullOrBlank() 之后的字符串
- android - 为什么我在 StringReader read() 中得到 IndexOutOfBoundsException?
- http - 与本地主机上的内部反向代理的内部 ServiceFabric 通信
- virtocommerce - 来自 Github 的 virto 商务部署
- html - CSS:强制无线电输入检查
- javascript - 在 Angular JS 中过滤我的 JavaScript 中的未定义