简体   繁体   中英

Trying to launch a webpage using Selenium in Python

I am trying to use selenium for Python and am having trouble running even a basic program just to get familiar with the selenium. For now, I am just trying to open a webpage and can't even get that to work. I know there are easier ways to launch a webpage with python, but my goal is to work with the webpage content later, so that is why I am using selenium.

from selenium import webdriver

browser = webdriver.Firefox()
browser.get("http://www.stackoverflow.com")

This results in this error message followed by launching a blank firefox window...

Traceback (most recent call last):
  File "C:\Python33\Learning Python\soundcloud_play.py", line 10, in <module>
    browser.get("http://www.stackoverflow.com")
  File "C:\Python33\lib\site-packages\selenium-2.38.4-py3.3.egg\selenium\webdriver\remote\webdriver.py", line 176, in get
self.execute(Command.GET, {'url': url})
  File "C:\Python33\lib\site-packages\selenium-2.38.4-py3.3.egg\selenium\webdriver\remote\webdriver.py", line 162, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Python33\lib\site-packages\selenium-2.38.4-py3.3.egg\selenium\webdriver\remote\remote_connection.py", line 349, in execute
    return self._request(url, method=command_info[0], data=data)
  File "C:\Python33\lib\site-packages\selenium-2.38.4-py3.3.egg\selenium\webdriver\remote\remote_connection.py", line 377, in _request
    resp = self._conn.getresponse()
  File "C:\Python33\lib\http\client.py", line 1143, in getresponse
    response.begin()
  File "C:\Python33\lib\http\client.py", line 354, in begin
    version, status, reason = self._read_status()
  File "C:\Python33\lib\http\client.py", line 324, in _read_status
    raise BadStatusLine(line)
http.client.BadStatusLine: ''

I don't understand what this problem is or how to go about fixing it. I am running Windows 7, Python 3.3.2, Selenium 2.38.4, Firefox 17.0.10

Any ideas would be greatly appreciated. Thanks.

Try upgrade your Firefox to 25 (recommended), or downgrade your Selenium to 2.27 (not recommended.)

Changelog is here .

Note that Selenium 2.39 just got out, which supports Firefox 26.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM