gpt4 book ai didi

python - 无法从福布斯抓取当天的报价

转载 作者:行者123 更新时间:2023-12-01 03:51:43 25 4
gpt4 key购买 nike

我正在尝试使用 python + Beautiful Soup 从福布斯网站上抓取当天的报价。

import requests
from bs4 import BeautifulSoup
import urllib.request

url = requests.get('http://www.forbes.com/quotes/1/')
url = url.text
soup = BeautifulSoup(url,'html.parser')
print(soup.find('p',{'class' : 'ng-binding'}))

当我运行此代码时,我得到输出:无

最佳答案

报价本身是从不同的资源 URL 动态加载的。向它发出请求,而不是解析 JSON 响应:

>>> import requests
>>>
>>> url = "http://www.forbes.com/forbesapi/thought/uri.json?enrich=true&query=1&relatedlimit=5"
>>> response = requests.get(url)
>>> data = response.json()
>>>
>>> data['thought']['quote'].strip()
u'Teach self-denial and make its practice pleasure, and you can create for the world a destiny more sublime that ever issued from the brain of the wildest dreamer.'

关于python - 无法从福布斯抓取当天的报价,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38129681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com