我的麻烦是firefox webdriver在特定的网页上停止响应。代码很简单:
import time
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://ok.ru')
lgn = 'tester919191'
pswd = 'tester919191!!@#@'
browser.find_element_by_css_selector('#field_email').send_keys(lgn)
browser.find_element_by_css_selector('#field_password').send_keys(pswd)
browser.find_element_by_css_selector('input.button-pro').click()
for i in xrange(100):
print i, browser.current_url
time.sleep(1)
我正在尝试签署俄罗斯社交网络。因此,大约10秒钟后,浏览器停止响应,解释器挂起browser.current_url
行。我曾尝试使用许多不同的firefox版本,但我仍然得到了相同的结果。我尝试使用的Selenium版本是2.45.0或2.44.0。我的假设是在这个页面上有一些JS代码崩溃了webdriver。顺便说一下,我的代码在主页面上完美运行(没有登录)。
更新
运行上面的代码我得到了以下结果:
0 http://ok.ru/
1 http://ok.ru/
2 http://ok.ru/
3 http://ok.ru/
4 http://ok.ru/
5 http://ok.ru/
6 http://ok.ru/
7 http://ok.ru/
8 http://ok.ru/
9
Traceback (most recent call last):
File "/Users/admin/Desktop/sele.py", line 15, in <module>
print i, browser.current_url
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 428, in current_url
return self.execute(Command.GET_CURRENT_URL)['value']
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 173, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 349, in execute
return self._request(command_info[0], url, body=data)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 380, in _request
resp = self._conn.getresponse()
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1045, in getresponse
response.begin()
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 409, in begin
version, status, reason = self._read_status()
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 373, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine: ''
翻译翻译约5分钟后出现例外情况。