Wan*_*ign 6 python selenium google-chrome web-scraping selenium-webdriver
我使用一个小的 python 脚本和 chrome 驱动程序从 Mangafox 下载漫画。它曾经运行良好,直到几天前我更新 Chrome 浏览器。现在每次尝试时都会显示以下错误:
[14664:14280:0420/202509.245:ERROR:browser_switcher_service.cc(238)] XXX Init()
[14664:14280:0420/202509.678:ERROR:device_event_log_impl.cc(162)] [20:25:09.679] Bluetooth: bluetooth_adapter_winrt.cc:1186 Getting Radio failed. Chrome will be unable to change the power state by itself.
[14664:14280:0420/202509.695:ERROR:device_event_log_impl.cc(162)] [20:25:09.696] Bluetooth: bluetooth_adapter_winrt.cc:1264 OnPoweredRadioAdded(), Number of Powered Radios: 1
[14664:14280:0420/202509.696:ERROR:device_event_log_impl.cc(162)] [20:25:09.696] Bluetooth: bluetooth_adapter_winrt.cc:1283 OnPoweredRadiosEnumerated(), Number of Powered Radios: 1
Run Code Online (Sandbox Code Playgroud)
我使用了带有 chrome 驱动程序的 selenium 模块。我尝试更新我的网络驱动程序,尝试使代码循环或休眠,直到网页完全加载。
我的代码如下:
from selenium import webdriver
import os
import urllib.request
Main = 'https://ww3.mangafox.online/'
Name = str(input('Enter Name of Manga as on \'ww3.Mangafox.online\': '))
Name = Name.replace(' ', '-')
Name = Name.replace('\'', '-')
driver = webdriver.Chrome(r'C:\Users\freak\Assignments\SDP\Drivers\chromedriver.exe')
driver.get(Main + Name)
Tags = driver.find_elements_by_tag_name('a')
List = []
for Tag in Tags:
List.append(str(Tag.get_attribute('href')))
dir = os.path.join('C:\\','Users', 'freak', 'Assignments', 'SDP', 'Test', Name.replace('-', '_'))
print('Checking the existence of folder; %s' % dir)
if not os.path.exists(dir):
print('Folder not found. Attempting to create folder: %s' % dir)
os.mkdir(dir)
print('Folder successfully created')
Index = []
for i, element in enumerate(List):
if (str(Name) + '/chapter') in element:
Index.append(i)
Chapters = []
Run Code Online (Sandbox Code Playgroud)
在这部分之后只是我用来下载图像的循环。但是由于某种原因,显示错误并且为标签创建的列表保持为空。将driver.find_elements_by_tag_name('a')
完全失效。
这些错误信息...
[14664:14280:0420/202509.245:ERROR:browser_switcher_service.cc(238)] XXX Init()
[14664:14280:0420/202509.678:ERROR:device_event_log_impl.cc(162)] [20:25:09.679] Bluetooth: bluetooth_adapter_winrt.cc:1186 Getting Radio failed. Chrome will be unable to change the power state by itself.
[14664:14280:0420/202509.695:ERROR:device_event_log_impl.cc(162)] [20:25:09.696] Bluetooth: bluetooth_adapter_winrt.cc:1264 OnPoweredRadioAdded(), Number of Powered Radios: 1
[14664:14280:0420/202509.696:ERROR:device_event_log_impl.cc(162)] [20:25:09.696] Bluetooth: bluetooth_adapter_winrt.cc:1283 OnPoweredRadiosEnumerated(), Number of Powered Radios: 1
Run Code Online (Sandbox Code Playgroud)
...暗示该on_init_
方法在std::make_unique<base::ScopedClosureRunner>(std::move(on_init))
.
这些错误在bluetooth_adapter_winrt.cc中定义如下:
获取无线电失败。Chrome 将无法自行更改电源状态:
void BluetoothAdapterWinrt::OnGetRadio(base::ScopedClosureRunner on_init,
ComPtr<IRadio> radio) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (radio) {
radio_ = std::move(radio);
radio_was_powered_ = GetState(radio_.Get()) == RadioState_On;
radio_state_changed_token_ = AddTypedEventHandler(
radio_.Get(), &IRadio::add_StateChanged,
base::BindRepeating(&BluetoothAdapterWinrt::OnRadioStateChanged,
weak_ptr_factory_.GetWeakPtr()));
if (!radio_state_changed_token_)
BLUETOOTH_LOG(ERROR) << "Adding Radio State Changed Handler failed.";
return;
}
// This happens within WoW64, due to an issue with non-native APIs.
BLUETOOTH_LOG(ERROR)
<< "Getting Radio failed. Chrome will be unable to change the power "
"state by itself.";
Run Code Online (Sandbox Code Playgroud)
有源无线电数量: 1:
void BluetoothAdapterWinrt::OnPoweredRadioAdded(IDeviceWatcher* watcher,
IDeviceInformation* info) {
if (++num_powered_radios_ == 1)
NotifyAdapterPoweredChanged(true);
BLUETOOTH_LOG(ERROR) << "OnPoweredRadioAdded(), Number of Powered Radios: "
<< num_powered_radios_;
}
void BluetoothAdapterWinrt::OnPoweredRadioRemoved(
IDeviceWatcher* watcher,
IDeviceInformationUpdate* update) {
if (--num_powered_radios_ == 0)
NotifyAdapterPoweredChanged(false);
BLUETOOTH_LOG(ERROR) << "OnPoweredRadioRemoved(), Number of Powered Radios: "
<< num_powered_radios_;
}
void BluetoothAdapterWinrt::OnPoweredRadiosEnumerated(IDeviceWatcher* watcher,
IInspectable* object) {
BLUETOOTH_LOG(ERROR)
<< "OnPoweredRadiosEnumerated(), Number of Powered Radios: "
<< num_powered_radios_;
// Destroy the ScopedClosureRunner, triggering the contained Closure to be
// run. Note this may destroy |this|.
DCHECK(on_init_);
on_init_.reset();
}
Run Code Online (Sandbox Code Playgroud)
这些错误是根据Chrome 中讨论中的详细信息与google-chrome合并的更改的直接影响,不再接受回退到通用名称的证书
确保这件事:
然而,据观察,可以通过在 Linux 上以root
用户 ( administrator
)身份运行 Chrome 来抑制此错误,但这与ChromeDriver - WebDriver for Chrome中提到的文档有偏差:
Chrome 在启动期间崩溃的一个常见原因是在 Linux 上以 root 用户(管理员)身份运行 Chrome。虽然可以通过在创建WebDriver会话时传递“--no-sandbox”标志来解决此问题,即ChromeDriver会话作为此类配置不受支持且极不鼓励。
理想情况下,您需要将环境配置为以普通用户身份运行 Chrome。
最后,根据Selenium Chrome 驱动程序:解决有关注册表项和实验选项的错误消息中的文档,可以通过添加参数来抑制这些错误日志:
excludeSwitches: ['enable-logging']
Run Code Online (Sandbox Code Playgroud)
所以你的有效代码块将是:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.google.com/")
Run Code Online (Sandbox Code Playgroud)
小智 0
您是否尝试过切换到 Firefox 驱动程序?
https://github.com/mozilla/geckodriver/releases
你只需要更新你的代码:
driver = webdriver.Firefox(executable_path='/path/to/driver')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7650 次 |
最近记录: |