作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 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/
我是一名优秀的程序员,十分优秀!