本文介绍了无法 requests.get() 一个网站,“远程结束连接没有响应"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试向该网站发送请求时:
when I try to send a request to this website:
import requests
requests.get('https://www.ldoceonline.com/')
返回异常
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
奇怪的部分是,如果您通过正常方法(通过浏览器)访问网站,它们功能齐全并且响应非常好.只有当您尝试通过网络抓取技术检索信息时,您才会遇到此响应.
The weird part is, if you access the website through normal approach(via a browser), they are fully functional and respond very well. Only when you try to retrieve information via web-scraping technique do you encounter this response.
知道如何成功抓取它吗?
Any idea on how to successfully scraping it?
推荐答案
尝试使用标头来获得所需的响应.
Try using a header to get the desired response.
import requests
res = requests.get('https://www.ldoceonline.com/',headers={"User-Agent":"Mozilla/5.0"})
print(res.status_code)
输出:
200
这篇关于无法 requests.get() 一个网站,“远程结束连接没有响应"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!