我坚持使用这个蟒蛇"想要机器人"。我谷歌几个小时但没有成功

时间:2017-08-11 17:11:58

标签: python python-3.x selenium selenium-webdriver webdriver

我正在尝试构建一个机器人并让它在树莓派3上运行。在Linux上它很有效但是一旦我把它移到Raspbian我就遇到了困难。我修正了一些错误,但是这个我可以通过互联网找到任何帮助。所以我发布了代码和错误。任何帮助,将不胜感激。我也上传了python目录的截图,也许有人注意到了什么问题。如果您认为可以帮助我,请询问您需要的任何信息。感谢。

以下脚本:

import io
import time
import urllib
from PIL import Image
from random import randint
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
####################################

while True:
    driver = webdriver.Firefox()
    driver.get("https://website.com")

    time.sleep(randint(1, 2))

    driver.find_element_by_class_name('login_menu').click()

    time.sleep(randint(1, 3))

    keyAddress = driver.find_element_by_id("login_form")
    keyAddress.send_keys("1NH6N2pT8LMZXz5GFPGgjW85aJ") #acc3

    time.sleep(randint(1, 4))

    password = driver.find_element_by_id("login_password")
    password.send_keys("password")

    time.sleep(randint(1, 3))

    driver.find_element_by_id("login_button").click()


    time.sleep(randint(1, 3))


    driver.find_element_by_class_name("captcha_input").click()

    time.sleep(randint(1, 2))

    driver.get_screenshot_as_file('/home/pi/Desktop/bot/pycap/screenshot.jpg')

    time.sleep(randint(2, 4))

    ####################################################
    ##############CAPTCHA SOLVING MODULE################
    ####################################################

    # Cropping captcha image 
    img = Image.open("screenshot.jpg")

    area = (495, 770, 720, 842)

    imgCropped = img.crop(area)
    imgCropped.save("media.jpg")

    time.sleep(randint(2, 4))

    # Sending image to DBC
    import deathbycaptcha

    # Put your DBC account username and password here.
    # Use deathbycaptcha.HttpClient for HTTP API.
    client = deathbycaptcha.SocketClient('username', 'password')
    try:
        balance = client.get_balance()

        # Put your CAPTCHA file name or file-like object, and optional
        # solving timeout (in seconds) here:
        captcha = client.decode('media.jpg', 60)
        if captcha:
            # The CAPTCHA was solved; captcha["captcha"] item holds its
            # numeric ID, and captcha["text"] item its text.
            print (captcha)
            if captcha:  # check if the CAPTCHA was incorrectly solved
                client.report(captcha["captcha"])
    except deathbycaptcha.AccessDeniedException:
        # Access to DBC API denied, check your credentials and/or balance

    ####################################################

            time.sleep(randint(4, 6))

    sendCaptcha = driver.find_element_by_class_name("captcha_input")
    sendCaptcha.click()

    time.sleep(randint(3, 5))

    solvedCaptcha = (captcha["text"])

    sendCaptcha.send_keys(str(solvedCaptcha))

    time.sleep(randint(1, 3))

    play = driver.find_element_by_id("play_button")
    play.click()

    time.sleep(randint(2, 4))


    driver.quit()

错误:

Traceback (most recent call last):
  File "/home/pi/Desktop/bot/pycap/looptest.py", line 6, in <module>
    from selenium import webdriver
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "/usr/local/lib/python3.4/dist-packages/selenium-3.4.3-py3.4.egg/selenium/webdriver/__init__.py", line 18, in <module>
    from .firefox.webdriver import WebDriver as Firefox  # noqa
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "/usr/local/lib/python3.4/dist-packages/selenium-3.4.3-py3.4.egg/selenium/webdriver/firefox/webdriver.py", line 34, in <module>
    from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "/usr/local/lib/python3.4/dist-packages/selenium-3.4.3-py3.4.egg/selenium/webdriver/remote/webdriver.py", line 25, in <module>
    from .webelement import WebElement
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "/usr/local/lib/python3.4/dist-packages/selenium-3.4.3-py3.4.egg/selenium/webdriver/remote/webelement.py", line 40, in <module>
    getAttribute_js = pkgutil.get_data(__package__, 'getAttribute.js').decode('utf8')
  File "/usr/lib/python3.4/pkgutil.py", line 611, in get_data
    spec = importlib.util.find_spec(package)
  File "/usr/lib/python3.4/importlib/util.py", line 81, in find_spec
    fullname = resolve_name(name, package) if name.startswith('.') else name
AttributeError: 'NoneType' object has no attribute 'startswith'

截图:

python directory

1 个答案:

答案 0 :(得分:0)

分析错误输出,它说:

  

'NoneType'对象没有属性'startswith'

当有人忘记向函数/方法添加return语句时,通常会发生此错误,因为标准返回值为String,如果未指定返回值。

高于此错误的一行,我们会看到此错误产生的位置:文件 /usr/lib/python3.4/importlib/util.py 的第81行中的变量None出于某种神奇的原因,name。因此,如果没有此文件,则无法知道Nonename的原因。

但是我假设你没有写这个文件,这些错误可能不是你的错,但这个 importlib 有问题,所以试着删除并重新安装这个库,或者如果它是一个本机库,然后重新安装python,当它不起作用时,可能尝试不同的python版本, 3.5 fe。