python与硒库的Webscraping错误

发布于 2025-01-21 19:50:36 字数 1806 浏览 0 评论 0原文

我尝试使用Selenium库来提取下面的数据,但不幸的是,我得到了下一个错误。有人可以帮助我吗?

从Selenium Import WebDriver中,

url = 'https://www150.statcan.gc.ca/n1/pub/71-607-x/2021004/exp-eng.htm?r1=(1)&r2=0&r3=0&r4=12&r5=0&r7=0&r8=2022-02-01&r9=2022-02-011'

driver = webdriver.Chrome()
driver.get(url)

table = driver.find_elements_by_class_name('data')

for table1 in table:
    value = table1.find_element_by_xpath('.//*[@id="report_table"]/tbody/tr[1]/td[6]').text
    quantity = table1.find_element_by_xpath('.//*[@id="report_table"]/tbody/tr[1]/td[7]').text
    unit = table1.find_element_by_xpath('.//*[@id="report_table"]/tbody/tr[1]/td[8]').text
    print(value, quantity, quantity)

错误是:

enter image description herePS C:\Users\asus\Desktop\home> [840:7000:0417/201023.654:ERROR:device_event_log_impl.cc(214)] [20:10:23.656] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[840:7000:0417/201023.654:ERROR:device_event_log_impl.cc(214)] [20:10:23.658] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[840:7000:0417/201023.654:ERROR:device_event_log_impl.cc(214)] [20:10:23.659] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[840:7000:0417/201023.659:ERROR:device_event_log_impl.cc(214)] [20:10:23.660] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[840:16136:0417/201113.924:ERROR:util.cc(126)] Can't create base directory: C:\Program Files\Google\GoogleUpdater

I tried to extract data the site below with selenium library but Unfortunately I got next error. is there anyone who can help me??

from selenium import webdriver

url = 'https://www150.statcan.gc.ca/n1/pub/71-607-x/2021004/exp-eng.htm?r1=(1)&r2=0&r3=0&r4=12&r5=0&r7=0&r8=2022-02-01&r9=2022-02-011'

driver = webdriver.Chrome()
driver.get(url)

table = driver.find_elements_by_class_name('data')

for table1 in table:
    value = table1.find_element_by_xpath('.//*[@id="report_table"]/tbody/tr[1]/td[6]').text
    quantity = table1.find_element_by_xpath('.//*[@id="report_table"]/tbody/tr[1]/td[7]').text
    unit = table1.find_element_by_xpath('.//*[@id="report_table"]/tbody/tr[1]/td[8]').text
    print(value, quantity, quantity)

the Error is:

enter image description herePS C:\Users\asus\Desktop\home> [840:7000:0417/201023.654:ERROR:device_event_log_impl.cc(214)] [20:10:23.656] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[840:7000:0417/201023.654:ERROR:device_event_log_impl.cc(214)] [20:10:23.658] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[840:7000:0417/201023.654:ERROR:device_event_log_impl.cc(214)] [20:10:23.659] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[840:7000:0417/201023.659:ERROR:device_event_log_impl.cc(214)] [20:10:23.660] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[840:16136:0417/201113.924:ERROR:util.cc(126)] Can't create base directory: C:\Program Files\Google\GoogleUpdater

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

牵你手 2025-01-28 19:50:36

只需手动创建目录:
c:\ program Files \ Google \ Googleupdater ”。
应该正常工作。

Just create the directory manually:
"C:\Program Files\Google\GoogleUpdater".
Should work properly.

呆° 2025-01-28 19:50:36

我认为,如果您还没有

驱动程序= webdriver.chrome(“您的WebDriver Path”)

I think you should link to your webDriver using its path if you haven't already

driver = webdriver.Chrome("your WebDriver Path")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文