Selenium chromedriver 错误:不允许启动 AudioContext。必须在页面上的用户手势后恢复(或创建)
我正在尝试访问此网站上的数据: https://vemcount.app/embed/embed/widget/widget/widget/uocrulpangwo5ft?localecale
到目前为止,我的代码如下:
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
def configure_driver():
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--use-fake-ui-for-media-stream")
driver = webdriver.Chrome(executable_path="C:\\Users\\uqiabde1\\Downloads\\chromedriver.exe", options = chrome_options)
return driver
def getNumber(driver):
# Step 1: Go to website
driver.get(f"https://vemcount.app/embed/widget/uOCRuLPangWo5fT?locale=en")
# wait for the element to load
try:
WebDriverWait(driver, 10).until(lambda s: s.find_element_by_id("flex items-center").is_displayed())
except TimeoutException:
print("TimeoutException: Element not found")
return None
# Step 2: Create a parse tree of page sources after searching
soup = BeautifulSoup(driver.page_source, "lxml")
# Step 3: Iterate over the search result and fetch the number
for number in soup.select("div.items-center"):
number_needed = "p span"
print({
"title": number.select_one(number_needed).text,
})
# create the driver object.
driver = configure_driver()
getNumber(driver)
# close the driver.
driver.close()
我在Chromedriver中收到以下错误
[0414/150051.086:信息:console(2)]“不允许启动AudioContext。必须在页面上的用户手势后恢复(或创建)。https:// goo [dot] gl/gl/gl/ 7k7wlu”,来源:(2)
我不确定要使用哪种chrome_option绕过此错误。我尝试了一些,例如
--no-user-gesture-required
,
--disable-gesture-requirement-for-presentation
您的帮助将不胜感激。 谢谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有相同的查询或在动态网络刮擦方面正在努力,我找到了一种无需使用
selenium
和bs4
而刮擦数据的方法。我使用的剧作家更加简单,并且非常感谢
innion_html()
函数,该功能直接读取到动态FLEX HTML代码中。这是供参考的代码。如果有一种更好的方法,我很乐意听到您的建议。
您的,
Python的初学者。 :)
Just in case you had the same query or were struggling with dynamic web scraping I found a way to scrape the data without using
selenium
andbs4
.I used playwright which is far more straightforward and has a very much appreciated
inner_html()
function which reads straight into the dynamic flex HTML code. Here is the code for reference.If there is a better way I am more than happy to hear your suggestions.
Yours,
A Beginner in Python. :)