【问题标题】:webdriver.chrome() TypeError: 'module' object is not callablewebdriver.chrome()类型错误:“模块”对象不可调用
【发布时间】:2020-03-18 03:32:43
【问题描述】:

我正在 python3 中处理亚马逊网络抓取脚本,所以我使用了 selenium,但我得到了这个调试

webdriver.chrome()
TypeError: 'module' object is not callable 

我看到了改变的解决方案(chrome 到 Chrome),但我也得到了这个调试

FileNotFoundError: [WinError 2] The system cannot find the file specified

这是我的代码

# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
from selenium import webdriver

driver = webdriver.chrome()
driver.get('https://www.amazon.com/international-sales-offers/b/?ie=UTF8&node=15529609011&ref_=nav_navm_intl_deal_btn')
res = driver.execute_script("return document.documentElement.outerHTML")
driver.quit()
soup = BeautifulSoup(res , 'lxml')
box= soup.find('div',{'class':'a-row padCenterContainer widgetBorder'})
products=box.find_all('div',{'class':'a-section a-spacing-none tallCellView gridColumn5 singleCell'})
for details in products:
    name= details.find('span',{'class':'a-declarative'}).text
    link= details.find('a',{'class':'a-size-base a-link-normal dealTitleTwoLine singleCellTitle autoHeight'}).get('href')
    print(name,link)

【问题讨论】:

  • 你下载chrome webdriver了吗?
  • 请提供整个错误信息。
  • 您能否提供完整的错误消息,以便我们更好地了解您遇到的错误?

标签: python selenium selenium-webdriver web-scraping scrapy


【解决方案1】:

我认为应该是Chrome(),而不是chrome()。试试:

from selenium import webdriver

driver = webdriver.Chrome()

您也可以将路径传递给您的 Chromedriver,将 executable_path 设置为您的 chromedriver 所在的位置(chromedriver.exe 的路径,或者,对于非 Windows 用户,它只是称为 chromedriver):

driver = webdriver.Chrome(executable_path='C:/path/to/chromedriver.exe')

【讨论】:

  • @EslamAhmed 我用另一个解决方案编辑了我的答案
  • 我工作了,但现在它没有给我任何我想要的部分的数据,并给我这个消息 ``` DevTools 监听 ws://127.0.0.1:65378/devtools/browser /4ff38b27-22be-4d7d-8fc8-f913a8b1090c ```
猜你喜欢
  • 1970-01-01
  • 2020-12-31
  • 1970-01-01
  • 1970-01-01
  • 2013-09-19
  • 1970-01-01
  • 1970-01-01
  • 2018-01-22
  • 1970-01-01
相关资源
最近更新 更多