【问题标题】:How to avoid freeze while scrape from CME webpage?从 CME 网页抓取时如何避免冻结?
【发布时间】:2023-01-02 21:44:20
【问题描述】:

我正在尝试从 CME 抓取数据,但代码似乎冻结在 requests.get() 函数处。

import requests
from bs4 import BeautifulSoup

URL = 'https://www.cmegroup.com/markets/interest-rates/us-treasury/2-year-us-treasury-note.settlements.html'
page = requests.get(URL)

【问题讨论】:

    标签: python web-scraping python-requests


    【解决方案1】:

    似乎他们正在检查user-agent

    User-Agent 请求标头是一个特征字符串,可让服务器和网络对等方识别请求用户代理的应用程序、操作系统、供应商和/或版本。

    不是特定的,所以只要给他们你最喜欢的代理:

    requests.get(URL, headers={'user-agent':'SALT'}).text
    

    更多关于 user-agent 查看 docs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-30
      • 1970-01-01
      • 1970-01-01
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多