尝试在Python中使用Selenium启动网页 [英] Trying to launch a webpage using Selenium in Python

查看:138
本文介绍了尝试在Python中使用Selenium启动网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将硒用于Python,甚至在运行基本程序时都难以熟悉硒.现在,我只是试图打开一个网页,甚至无法正常工作.我知道使用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")

这会导致出现此错误消息,然后启动空白的Firefox窗口...

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: ''

我不知道这个问题是什么或如何解决.我在跑步 Windows 7的, Python 3.3.2, 硒2.38.4 Firefox 17.0.10

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.

推荐答案

尝试将Firefox升级到25(推荐),或将Selenium降级到2.27(不推荐).

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

Changelog在此处.

Changelog is here.

请注意,Selenium 2.39刚发布,它支持Firefox 26.

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

这篇关于尝试在Python中使用Selenium启动网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆