Python BeautifulSoup extract建议的文本条目(在html中不可见)

2024-06-24 12:40:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从这个网站上提取一个数字

http://www.mycryptobuddy.com/BitcoinMiningCalculator

website and html picture

我试图使用beautifulsoup在一个输入字段中提取这个数字,其中显示“3511.0”(如图所示),但是这在html中是不可见的。你知道吗

我怎样才能用beautifulsoup提取这个数字?你知道吗

我的代码:

from urllib import request
from bs4 import BeautifulSoup

html = 'http://www.mycryptobuddy.com/BitcoinMiningCalculator'
page = request.urlopen(html)
soup = BeautifulSoup(page, 'html.parser')
dif = soup.find('input', attrs={'ng-model': 'difficulty'})

print(dif.get('value'))
print(dif.attrs)

输出:

None
{'type': 'number', 'ng-model': 'difficulty', 'ng-change': 'computeProfits(); turnAutoUpdateOff()'}
Process finished with exit code 0

Tags: fromimportcomhttprequesthtmlwwwpage
1条回答
网友
1楼 · 发布于 2024-06-24 12:40:15

在html中找不到这个数字的原因是它不在那里,它是通过javascript通过位于ws://185.185.40.128:1235的websocket接收到的/套接字.io/ 正如你在这张图片上看到的:

如果你想得到这些数字,你应该连接到websocket,并解析传入的消息。你知道吗

相关问题 更多 >