【问题标题】:get requests is not loading in python获取请求未在 python 中加载
【发布时间】:2021-03-20 18:46:40
【问题描述】:

我正在尝试从以下网站获取数据。 https://www1.nseindia.com/products/dynaContent/common/productsSymbolMapping.jsp?symbol=SBIN&segmentLink=3&symbolCount=2&series=EQ&dateRange=+&fromDate=01-01-2020&toDate=31-12-2020&dataType=PRICEVOLUMEDELIVERABLE

我尝试了以下方法:

  1. 在请求中获取整个 url:
response = requests.get('https://www1.nseindia.com/products/dynaContent/common/productsSymbolMapping.jsp?symbol=SBIN&segmentLink=3&symbolCount=2&series=EQ&dateRange=+&fromDate=01-01-2020&toDate=31-12-2020&dataType=PRICEVOLUMEDELIVERABLE')
  1. 获取基础网页并添加参数:
response = requests.get('https://www1.nseindia.com/products/dynaContent/common/productsSymbolMapping.jsp', params = {'symbol':'SBIN','segmentLink':'3','symbolCount':'2','series':'EQ','dateRange':' ','fromDate':'01-01-2020','toDate':'31-12-2020','dataType':'PRICEVOLUMEDELIVERABLE'})
  1. 使用了 urllib:
f = urllib.request.urlopen('https://www1.nseindia.com/products/dynaContent/common/productsSymbolMapping.jsp?symbol=SBIN&segmentLink=3&symbolCount=2&series=EQ&dateRange=+&fromDate=01-01-2020&toDate=31-12-2020&dataType=PRICEVOLUMEDELIVERABLE')

以上方法均无效。 他们只是无限期地加载。

提前致谢。

【问题讨论】:

  • 当我打开链接时,它说 GET 方法未授权
  • 设置常用浏览器的用户代理头!
  • 检查你的网址...似乎你有 www1 而不是 www

标签: python python-3.x python-requests urllib


【解决方案1】:

不要忘记将 User-Agent 添加到请求标头中,如下所示:

header = {
        'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0',
        "X-Requested-With": "XMLHttpRequest"
    }
response = requests.get('you_url', headers=header)
print(response)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-05
    • 2020-07-29
    • 2020-04-01
    • 1970-01-01
    • 2012-09-29
    • 2018-08-01
    • 1970-01-01
    相关资源
    最近更新 更多