使用Python在Web取消过程中未显示的跨度标签中的数字值?

发布于 2025-02-06 03:53:05 字数 1346 浏览 2 评论 0原文

我是网络刮擦的新手。

我正在尝试从

我的代码是:

import requests
from bs4 import BeautifulSoup as bs

url = 'https://www.dailyfx.com/sentiment'

all_pages_reviews = []
response = requests.get(url)
soup = bs(response.content, 'html.parser')

rev_div = soup.findAll("span",attrs={"class","dfx-rateDetail__percentageInfoText font-weight-bold"})

print(rev_div)

这给出了Rev_div为“ bs4.element.ResultSet”,以下输出:

</span>, <span class="dfx-rateDetail__percentageInfoText font-weight-bold" data-market-id="GBPUSD" data-sort-column="sentiment-long" data-stream-type="sentiment" data-type="long-value-info" data-value="--">

</span>, <span class="dfx-rateDetail__percentageInfoText font-weight-bold" data-market-id="FR40" data-sort-column="sentiment-short" data-stream-type="sentiment" data-type="short-value-info" data-value="--">

”

问题是而是数字值' - ' 'data_value'。

我的目标是根据“ data-market-id”('gbpusd','fr40')找到“数据值”。

任何潜在客户都将不胜感激。

I am new to web scraping.

I am trying to download the Net Long position from https://www.dailyfx.com/sentiment site. The value is situated in div with class 'dfx-technicalSentimentCard__netLongContainer' and span attribute 'data-value'.

enter image description here

My code is:

import requests
from bs4 import BeautifulSoup as bs

url = 'https://www.dailyfx.com/sentiment'

all_pages_reviews = []
response = requests.get(url)
soup = bs(response.content, 'html.parser')

rev_div = soup.findAll("span",attrs={"class","dfx-rateDetail__percentageInfoText font-weight-bold"})

print(rev_div)

This gives rev_div as "bs4.element.ResultSet" with following output:

</span>, <span class="dfx-rateDetail__percentageInfoText font-weight-bold" data-market-id="GBPUSD" data-sort-column="sentiment-long" data-stream-type="sentiment" data-type="long-value-info" data-value="--">

</span>, <span class="dfx-rateDetail__percentageInfoText font-weight-bold" data-market-id="FR40" data-sort-column="sentiment-short" data-stream-type="sentiment" data-type="short-value-info" data-value="--">

enter image description here

The problem is instead of a numeric value '--' is shown for 'data_value'.

My goal here is to find 'data-value' as per 'data-market-id' ('GBPUSD', 'FR40').

Any lead will be highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文