【问题标题】:How to access network tab in chrome developer tools using python如何使用 python 访问 chrome 开发人员工具中的网络选项卡
【发布时间】:2020-09-01 12:10:33
【问题描述】:

我正在尝试从网站下载视频,他们使用一家名为 ooyala 的公司来托管他们的视频,所以我认为您无法通过搜索页面上的元素找到它。我正在尝试使用 selenium 单击播放按钮,并通过网络选项卡获取视频的 url。 这是我目前的代码

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities


def get_link():
    chrome_options = Options()
    chrome_options.add_experimental_option("detach", True)
    caps = DesiredCapabilities.CHROME
    caps['loggingPrefs'] = {'browser': 'ALL'}
    url_main = r'https://www.channelnewsasia.com/news/video-on-demand/japanhour'
    path = r'C:\Users\User\Downloads\Internet download\chromedriver_win32\chromedriver.exe'
    driver = webdriver.Chrome(path, chrome_options=chrome_options,desired_capabilities=caps)
    driver.get(url_main)
    time.sleep(10)
    link = driver.find_element_by_class_name('video__custom-duration')
    link.click()
    while True:
        for entry in driver.get_log('browser'):
            print(entry)

点击有效,但 loggingPrefs 无效,我认为它正在返回错误消息。我试图查找文档,但找不到其他类型的 args 进入 DesiredCapabilities 字典。谁能给我一些帮助?

TLDR:

如何在 chrome 中读取网络标签?

附加信息。

我使用的网址仅限于新加坡,所以这是另一个随机视频,供任何帮助我的人使用,但不使用 ooyala。 https://www.rollingstone.com/music/music-news/norwegian-dj-cashmere-cat-goes-spartan-on-with-me-premiere-71196/

如果您使用 vpn 访问原始网址,这是我试图自动查找的链接 https://mediacorp-videosaz.akamaized.net/c642f1d9-bfcd-46fe-8304-b4bf5c236d1e/BsY3hkajE6J_wuuYqP4M6HATpdD8CwlF.ism/QualityLevels(1984000)/Manifest(format=m3u8-aapl)

【问题讨论】:

  • 我相信在 pyautoit 的帮助下,您将能够在浏览器上执行操作以在开发人员工具中打开网络选项卡。 pypi.org/project/PyAutoIt
  • 我通过使用鼠标自动化搜索网络选项卡,单击我要查找的 url 出现的位置然后复制它,从而克服了一个糟糕的解决方案的问题。然后我使用 tkinter clipboard.get 从剪贴板获取 url。我仍在寻找更好的解决方案。

标签: python selenium google-chrome


【解决方案1】:

我使用 Selenium 来手动获取用于在网络选项卡中搜索的信息。

查看下面的链接了解更多详情

https://stackoverflow.com/a/68363046/8491363

Selenium 4.0 将正式支持访问 Chrome Devtool 信息,但仍处于测试阶段。在 3.0 上,您可以按照我的建议尝试记录性能。

【讨论】:

    猜你喜欢
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    • 2016-09-22
    • 1970-01-01
    • 2018-09-12
    • 2018-04-06
    • 2018-04-29
    • 2019-07-22
    相关资源
    最近更新 更多