Browser() in Python shows errors in IDLE

2019-09-07 15:58发布

问题:

I have some code here which is basically a bot that spams a specific google form:

while True:
    browser = Browser()
    print("Form Filling Begun")
    browser.visit('https://docs.google.com/forms/d/1Lyoox1FIpOP5nceVHqmdA3Exqf8PMCxaBgWIYQ67yX8/viewform?c=0&w=1')
    browser.fill('entry.1796849606', 'test')
    browser.fill('entry.1233774681', 'test')
    browser.fill('entry.1687034525', 'test')
    browser.fill('entry.2085519362', 'test')
    browser.fill('entry.2085519362', 'test')
    browser.fill('entry.87435301', 'test')
    browser.find_by_name('entry.434307791', 'test')
    browser.find_by_name('submit').click()
    print("Form Filled")
    browser.quit()
    time.sleep(10)

When I ran it in IDLE, it said there was a problem on line 2. That Browser() wasn't defined. Now, I know that my friend was able to accomplish this with this code, so I'm not sure what's wrong. I'm sure it's a really basic problem, but I'm a complete n00b at Python, so I don't really know what to do.

Thanks,

Sam.

EDIT: So I went on the Splinter website and put its own sample code in IDLE, to see what happens and this is what the console was showing

Traceback (most recent call last):
  File "C:/Users/Sam/Desktop/test.py", line 3, in <module>
    with Browser() as browser:
  File "C:\Python27\lib\site-packages\splinter\browser.py", line 63, in Browser
    return driver(*args, **kwargs)
  File "C:\Python27\lib\site-packages\splinter\driver\webdriver\firefox.py", line 39, in __init__
    self.driver = Firefox(firefox_profile)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 82, in __init__
    keep_alive=True)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 87, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 141, in start_session
    'desiredCapabilities': desired_capabilities,
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response
    raise exception_class(message, screen, stacktrace)
WebDriverException: Message: a.addEventListener is not a function

I'm out of my depth here. When it opened a browser window, the URL was about:blank&utm_content=firstrun. What does that mean??

回答1:

Do you import browser? Try:

from splinter.browser import Browser