将selenium与python beautifulsoup库一起使用时出现回溯错误

将selenium与python beautifulsoup库一起使用时出现回溯错误,python,selenium,selenium-webdriver,beautifulsoup,bs4,Python,Selenium,Selenium Webdriver,Beautifulsoup,Bs4,我使用此代码从链接中删除一些数据。因为我想在加载15秒后提取带有标记的实际脚本,所以有人建议我在代码中引入一个延迟。因此我使用这个代码 代码如下 #!/usr/bin/python import urllib import time from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from bs4 import BeautifulSoup from dateutil.pa

我使用此代码从链接中删除一些数据。因为我想在加载15秒后提取带有标记的实际脚本,所以有人建议我在代码中引入一个延迟。因此我使用这个代码

代码如下

#!/usr/bin/python
import urllib
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from bs4 import BeautifulSoup
from dateutil.parser import parse
from datetime import timedelta
import MySQLdb
import re
import pdb
import sys
import string



driver = webdriver.Firefox()
driver.get('https://website.grader.com/results/dubizzle.com')
time.sleep(25)
html = driver.page_source
soup  = BeautifulSoup(html)


# print soup

Sizeofweb=""
try:

    Sizeofweb= soup.find('span', {'data-reactid': ".0.0.3.0.0.3.$0.1.1.0"}).text
    print Sizeofweb.get_text().encode("utf-8")

except StandardError as e:
    converted_date="Error was {0}".format(e)
    print converted_date
我提取的html部分如下所示

#!/usr/bin/python
import urllib
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from bs4 import BeautifulSoup
from dateutil.parser import parse
from datetime import timedelta
import MySQLdb
import re
import pdb
import sys
import string



driver = webdriver.Firefox()
driver.get('https://website.grader.com/results/dubizzle.com')
time.sleep(25)
html = driver.page_source
soup  = BeautifulSoup(html)


# print soup

Sizeofweb=""
try:

    Sizeofweb= soup.find('span', {'data-reactid': ".0.0.3.0.0.3.$0.1.1.0"}).text
    print Sizeofweb.get_text().encode("utf-8")

except StandardError as e:
    converted_date="Error was {0}".format(e)
    print converted_date
捕捉:


1.1
兆字节
我安装geckodriver的方法是:从这里下载geckodriver并将其解压缩到/home目录,然后根据@Ahn Smith推荐的路径export path=$path:/home/geckodriver

现在当我运行程序时,它给出了这个错误

Traceback (most recent call last):
  File "ahmed.py", line 17, in <module>
    driver = webdriver.Firefox()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 140, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  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
回溯(最近一次呼叫最后一次):
文件“ahmed.py”,第17行,在
driver=webdriver.Firefox()
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/firefox/webdriver.py”,第140行,在__
self.service.start()
文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py”,第74行,开始
stdout=self.log\u文件,stderr=self.log\u文件)
文件“/usr/lib/python2.7/subprocess.py”,第710行,在__
错误读取,错误写入)
文件“/usr/lib/python2.7/subprocess.py”,第1327行,在执行子进程中
引发子对象异常
OSError:[Errno 20]不是目录

有两种方法可以将Selenium指向相应的Web驱动程序。您可以将其作为参数传递:

driver = webdriver.Firefox(executable_path='/path/to/geckodriver')
或者,您可以创建一个包含
路径的局部shell变量

$ export PATH=$PATH:/path/to/

我认为您的问题是,您正在将
路径
变量导出到geckodriver,而不是导出到包含它的文件夹。

路径/到/应该是这样吗?geckodriver在主目录中,因此我应该将driver=webdriver.Firefox(executable_path='/path/to/geckodriver')作为
executable_path
参数传递,则应该包含包含geckodriver的完整路径。如果在shell中添加
PATH
变量,您应该只包含包含geckodriver的目录的路径。请检查我的答案中的代码和错误。我已将geckodriver放入主目录尝试重新启动。如果失败,请尝试检查您的权限以确保geckodriver是可执行的。(或者尝试将其复制到/usr/local/sbin/)