Webdriver引发了http

Webdriver引发了http

本文介绍了Python Webdriver引发了http.client.BadStatusLine错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个解析器,我正在使用Selenium Webdriver。所以,我有这个代码,它的工作正常,直到一个随机元素和抛出以下例外:
http.client.BadStatusLine:''

根本不知道如何解决它。帮助。



[UPD]



我尝试通过webdriver滚动页面(它必须导致加载缩略图),并获得此错误系列。这将是由加载的图像之一的HTTP错误引起的,但我没有在页面上找到任何加载错误。仍然搜索答案。

解决方案

这是一个 urllib 问题。这在python3中最常见。这意味着服务器返回的状态代码不能被http库识别。有时,服务器根本没有收到请求,状态代码返回一个触发该错误的空字符串。



如何修复



检查URL字符串是否具有尾随的换行符。确保您的网址被剥离任何前导或尾随的特殊字符。更多信息



如果一切看起来都很好,网址只是处理例外

  import http 
try :
browser.get(MONTHLY_URL)
除了http.client.HTTPException为e:
打印e


I'm writing a parser and I'm using Selenium Webdriver. So, I have this https://repl.it/Dgtp code and it's working fine until one random element and throws following exception:http.client.BadStatusLine: ''
Don't know how to fix it at all. Help.

[UPD]

I tried to scroll the page via webdriver (it had to cause thumbnails to load) and got this https://repl.it/DkiX error series. It would be caused by HTTP error from one of images which were loading, but I've not found any loading errors on the page. Still searching the answer.

解决方案

This is a urllib problem. This happens most commonly in python3. What it means is that the status code that the server returned isn't recognized by the http library. Sometimes the server doesn't receive the request at all and the status code returns an empty string triggering that error.

How to fix

Check if the URL string has a trailing newline character. Make sure that your URLs are stripped of any leading or trailing special characters. More info here

If everything looks fine with the URL just treat the exception

import http
try:
    browser.get(MONTHLY_URL)
except http.client.HTTPException as e:
    print e

这篇关于Python Webdriver引发了http.client.BadStatusLine错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 13:44