【发布时间】:2020-10-18 23:21:26
【问题描述】:
我正在尝试从网页的表格中提取一些动态值。 This image 代表我希望从该页面获取的值。应该有任何方法可以使用请求来获取它们。为了让您知道,我在开发工具中查找了任何隐藏的 api,并通过页面源中的脚本标签找出了值,但我找不到。
这是site url
这是我想要的expected output。
这是我到目前为止写的:
import requests
from bs4 import BeautifulSoup
url = "https://www.dailyfx.com/sentiment"
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'}
r = requests.get(url,headers=headers)
soup = BeautifulSoup(r.text,"lxml")
for items in soup.select(".dfx-technicalSentimentCard__barContainer"):
data = [item.get("data-value") for item in items.select("[data-type='long-value-info'],[data-type='short-value-info']")]
print(data)
上面的脚本产生如下的空输出:
['--', '--']
['--', '--']
['--', '--']
['--', '--']
['--', '--']
['--', '--']
['--', '--']
如何使用请求从该表中获取值?
【问题讨论】:
-
我已经在上面的帖子中提到了您在@AMC 的回答中所写的内容。无论如何都是一个无用的链接。
-
我不明白,什么意思?我在您的帖子中看不到与我链接的问题相关的任何内容。
-
这条线是什么意思
analyze the network traffic for the data you need and make the requests directly?这才是我真正的问题。谢谢。 -
它将使用
Ajax来加载页面。如果您不想使用selenium,则需要找到AjaxAPI并获取您需要的数据。
标签: python web-scraping beautifulsoup python-requests