python - unable to requests.get() a website, 'Remote end closed connection without response'
问题描述
when I try to send a request to this website:
import requests
requests.get('https://www.ldoceonline.com/')
An exception returned
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?
解决方案
尝试使用标头来获得所需的响应。
import requests
res = requests.get('https://www.ldoceonline.com/',headers={"User-Agent":"Mozilla/5.0"})
print(res.status_code)
输出:
200
推荐阅读
- php - 注释行之间的匹配
- java - 如何使用 SoapUi 和 Spring boot 自动化 API 测试
- .net-core - 为这项工作准备代理。代理未在 Devops 上运行
- git - 将工作树转换回正常的 git 结构
- javascript - React Native 在组件之间添加间距
- java - 如何在 Java 中使用 selenium Web 驱动程序查找突出显示的文本?
- c# - 使用 Entity Framework Core 编写计算成员
- python - 如何使用python用大小为(8,8)的二维数组替换数组最后一列的前8个元素(大小=(8,8,3))
- grep - 避免在 grep 结果中使用破折号
- flutter - 如何为 gitlab 代码编辑器添加 Flutter 支持