python脚本获取错误

时间:2018-02-20 20:09:23

标签: python selenium selenium-webdriver

我在python中有新功能。我在ubuntu 14.04 system.i上安装了python,安装了selenium.webdriver ..但我收到了以下错误

  Traceback (most recent call last):
 File "test.py", line 12, in <module>
  with closing(Firefox()) as browser:
 File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__
  self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
 File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 20] Not a directory

我试过以下代码:

        from contextlib import closing
        from selenium.webdriver import Firefox
        from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
        from selenium.webdriver.support.ui import WebDriverWait
        from time import sleep
        from bs4 import BeautifulSoup
        import json

        url = "https://www.homedepot.ca/homedepotcacommercewebservices/v2/homedepotca/products/1000807160/localized/9999/"


        with closing(Firefox()) as browser:
             driver.get(url)
             sleep(3)
             Raw_data_buttom = browser.find_element_by_id("tab-1")
             Raw_data_buttom.click()
             soup = BeautifulSoup(browser.page_source, "html.parser")
             data = json.loads( soup.find("pre", "data").get_text() )
             print(data)

1 个答案:

答案 0 :(得分:0)

您需要在计算机上安装Firefox和geckodriver,并且可以在PATH环境变量上使用。

有关详细信息,请参阅Poloq's answer