- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Python 2.7 中的 Selenium 2.53.5 在在线表单中自动注册序列号。该脚本已经运行了 2 个多月,但昨天我在运行它时开始收到错误消息:httplib.BadStatusLine: ''。有什么已知的解决方法吗?我读过前导/尾随换行符可能会扰乱 url 的检索,但我似乎无法确定问题所在。
代码:
import sys
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
class SerialSet:
def __init__(self, fileName, driverPath, user, password):
self.fn = fileName
self.failedSerials = []
self.driver = webdriver.Chrome(driverPath)
self.aloSuccess = False
self.user = user
self.password = password
def parseSerialFile(self):
with open(self.fn, 'r') as f:
self.serials = [line.strip() for line in f]
def setCountrySN(self, serial, driver):
driver.find_element_by_xpath("//select/option[@value='USA']").click()
driver.find_element_by_id("serialno").send_keys(serial)
driver.find_element_by_xpath("//input[@value='Continue'][@type='button']").click()
def submitState(self, driver):
driver.find_element_by_xpath("//select/option[@value='CT']").click()
driver.find_element_by_id("Continue1").click()
def login(self, driver):
driver.find_element_by_xpath("//*[@id='accountname']").send_keys(self.user)
driver.find_element_by_xpath("//*[@id='accountpassword']").send_keys(self.password)
driver.find_element_by_xpath("//*[@id='signInHyperLink']").click()
def initiateSN(self, serial, driver):
# select country and enter serialno
driver.get("http://supportform.apple.com/201110/")
self.setCountrySN(serial, driver)
# enter login
time.sleep(3)
if driver.current_url == "http://supportform.apple.com/201110/":
return False
self.login(driver)
# select state and continue
time.sleep(3)
self.submitState(driver)
# final submit
time.sleep(3)
driver.find_element_by_id("finalContinue").click()
return True
def newSN(self, serial, driver):
# select country and enter serialno
driver.get("http://supportform.apple.com/201110/")
self.setCountrySN(serial, driver)
# select state and continue
time.sleep(3)
if driver.current_url == "http://supportform.apple.com/201110/":
return False
self.submitState(driver)
# final submit
time.sleep(3)
driver.find_element_by_id("finalContinue").click()
return True
def automateSerials(self):
for i in self.serials:
if self.aloSuccess == False:
if not self.initiateSN(i, self.driver):
self.failedSerials.append(i)
del i
else:
self.aloSuccess = True
else:
if not self.newSN(i, self.driver):
self.failedSerials.append(i)
del i
self.driver.quit()
print(str(len(self.serials) - len(self.failedSerials)) + ":" + str(len(self.serials)))
def main():
newSet = SerialSet(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
newSet.parseSerialFile()
newSet.automateSerials()
if __name__ == "__main__":
main()
错误:
Traceback (most recent call last):
File "automate.py", line 90, in <module>
main()
File "automate.py", line 85, in main
newSet = SerialSet(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
File "automate.py", line 11, in __init__
self.driver = webdriver.Chrome(driverPath)
File "/Library/Python/2.7/site- packages/selenium/webdriver/chrome/webdriver.py", line 67, in __init__
desired_capabilities=desired_capabilities)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 90, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 177, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 234, in execute
response = self.command_executor.execute(driver_command, params)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 401, in execute
return self._request(command_info[0], url, body=data)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 432, in _request
resp = self._conn.getresponse()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1132, in getresponse
response.begin()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 453, in begin
version, status, reason = self._read_status()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 417, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine: ''
最佳答案
确保您使用的是最新版本的 chromedriver: http://chromedriver.storage.googleapis.com/2.25/chromedriver_linux64.zip
我安装了 chromedriver 2.0 并遇到了这个错误,
当我升级到 2.25 时,它消除了这个错误。
关于python - Selenium 2.53.5 httplib.BadStatusLine : '' Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40286393/
我在 python 中使用 selenium 抓取一个网站,当我在 Windows 上运行相同的脚本时我得到了想要的结果,但是在 ubuntu 16.04 中当我运行相同的脚本时它抛出错误: File
我正在使用 suds 0.3.6。创建 suds 客户端时,随机出现错误: httplib.py,_read_status(),第 355 行,类 httplib.BadStatusLine' 这是用
我遇到了一个奇怪的错误,我似乎找不到解决方案。 这个错误不会在我每次点击这段代码时发生,也不会在循环中的同一次迭代中发生(它发生在一个循环中)。如果我运行够了,它似乎没有遇到错误,程序执行成功。无论如
一如既往,我经常遇到问题,我已经彻底搜索了当前问题的答案,但发现自己一头雾水。以下是我搜索过的一些地方:- How to fix httplib.BadStatusLine exception?- P
我将 PhantomJS 与 Selenium 结合使用,我想在 stackoverflow 上进行多次搜索。这段代码在我的本地电脑上运行良好,当我将它更改为内存较少的服务器时,它会引发 httpli
通过 python-requests 进行身份验证的代理返回以下错误: >>> import requests >>> proxies = {'https': 'http://username:pas
我正在尝试使用 Selenium 和 BeautifulSoup 抓取 Google Chrome 扩展商店的评论。但是,即使使用最新版本的 Chromedriver,我似乎也无法启动和运行 Sele
我这里有一个程序可以传输市场价格并根据价格执行订单,但是,每隔一段时间(几个小时左右)它就会抛出这个错误: Exception in thread Thread-1: Traceback (most
我正在尝试连接到groovyshark。因为 python 是我选择的语言。但我已经碰壁了。看来groveshark最近改变了他们的协议(protocol)的一部分,或者我可能遇到了python的限制
URL = "MY HTTP REQUEST URL" XML = "0" parameter = urllib.urlencode({'XML': XML}) response = urllib.u
我使用以下代码从网络获取图像: path = 'http://domgvozdem.ru/images/ustanovka-kondicionera-svoimi-rukami.jpg' def ex
我一生都无法弄清楚为什么我不能捕获这个异常。 查看此处this guide . def get_team_names(get_team_id_url, team_id): print(get_
我正在尝试使用 python-rest-client ( http://code.google.com/p/python-rest-client/wiki/Using_Connection ) 来执行
我一直在使用 Python 中的 requests 库查询 Web 服务器上的数据。我收到以下错误: ConnectionError: ('Connection aborted.', BadStatu
在 python 中,如果我导入请求并执行: t = requests.get("http://www.azlyrics.com/u/urban.html") 我得到这个异常: raise BadSt
我有一个简单的互联网检查器正在运行,但它偶尔会返回一个我似乎无法处理的错误... 函数如下: def internet_on(): try: urllib2.urlopen("
在我的 python 项目中,我使用 Splinter ( https://splinter.readthedocs.io/en/latest/ ) 打开浏览器并尝试访问网站: from splint
这个错误已经困扰我几个小时了。我决定编写一个单独的项目,看看我是否可以复制它,我可以,但只能在我的服务器上。这适用于我的 Mac。 Mac:OSX El Capitan 10.11.6 服务器:Cen
我在 Python 中使用请求,但总是遇到 BadStatusLine 错误。 我的代码如下: import requests ip = 'xx.xx.xx.xx' port = 80 proxies
尝试从 URL 获取数据,但请求遇到问题。我认为它与页面或数据的格式(没有)有关? 我使用的是Python 3.6.5,请求2.20.0 import requests r = requests.ge
我是一名优秀的程序员,十分优秀!