【问题标题】:Bluetooth: bluetooth_adapter_winrt.cc Getting Default Adapter failed蓝牙:bluetooth_adapter_winrt.cc 获取默认适配器失败
【发布时间】:2020-09-03 07:16:36
【问题描述】:

我正在学习如何使用 selenium 和 python ,我想爬取这个website的新闻标题和新闻日期
但我有一个问题,我不知道如何解决。

这是我的代码:

from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd  
import time
import json
driver = webdriver.Chrome("./chromedriver")
driver.implicitly_wait(10)
driver.get("https://www.thestandnews.com/search/?q=%E6%96%B0%E5%86%A0%E8%82%BA%E7%82%8E")
soup = BeautifulSoup(driver.page_source, "lxml")
pages_remaining = True
page_num = 1

My_array = []
while pages_remaining:
 print("Page Number:", page_num)

 soup = BeautifulSoup(driver.page_source, "lxml")
""" #undoned

 tags_lis = soup.find_all("li")
 for tag in tags_lis:
    tag_a = tag.find("a")
    tag_span = tag.find("span")
    title = tag_a.text
    date = tag_span.text
    temp = {"title": title , "date": date}
    print(temp)
    My_array.append(temp)
   """
  try:
    #Press button of next page
    #next_link =driver.find_element_by_xpath()
    nextPg = '//*[@id="___gcse_1"]/div/div/div/div[5]/div[2]/div/div/div[2]/div/div[%d]' % (page_num + 1)
    print(nextPg)
    next_link = driver.find_element_by_xpath(nextPg)
    next_link.click()

    time.sleep(5)
    if page_num < 10:
        page_num = page_num + 1
    else:
        pages_remaining = False
  except Exception:
    pages_remaining = False 
driver.close() 

这是错误信息,谁能给个提示,谢谢!

DevTools listening on ws://127.0.0.1:49952/devtools/browser/749fcb19-d13a-4f38-9d7c-3da58726e10a
[13744:13732:0517/214816.873:ERROR:browser_switcher_service.cc(238)] XXX Init()
Page Number: 1
//*[@id="___gcse_1"]/div/div/div/div[5]/div[2]/div/div/div[2]/div/div[2]
[13744:13732:0517/214824.321:ERROR:device_event_log_impl.cc(162)] [21:48:24.321] Bluetooth: 
bluetooth_adapter_winrt.cc:1055 Getting Default Adapter failed.
Page Number: 2
//*[@id="___gcse_1"]/div/div/div/div[5]/div[2]/div/div/div[2]/div/div[3]

【问题讨论】:

  • 我也有类似的问题,请问您找到解决方法了吗? -- 我的问题 --- 蓝牙:bluetooth_adapter_winrt.cc:713 GetBluetoothAdapterStaticsActivationFactory 失败:类未注册(0x80040154)
  • 我用的是 firefox
  • 您是否尝试过其他浏览器?或者 webdriver-manager 包什么会自动安装 chromedriver?

标签: python selenium


【解决方案1】:

我不确定该网站是否仍然正常运行(我无法阅读通知,因为它不是英文的)。无论如何,如果 try 块不起作用,即如果元素未找到或不可点击,则 except 块将触发,我对此进行了权衡,并测试了您的代码。 我在运行时没有在终端中看到任何与蓝牙相关的错误;但是,如果您只是想在运行代码时忽略该信息/错误或试图绕过它记录在终端中,那么您必须使用 Options 中的实验选项。

from selenium.webdriver.chrome.options import Options
chr_options = Options()
chr_options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(executable_path = "your driver path", options = chr_options)

这应该可以抑制蓝牙相关的错误/信息显示在终端上。

写答案,因为我没有足够的代表来评论查询。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-31
    相关资源
    最近更新 更多