使用 Python/BS 进行实时数据 HTML 解析 | 珊瑚贝

Live data HTML parsing with Python/BS


我已经搜索这些页面好几天都没有成功,所以我希望这不是重复的。如果是这样我道歉。
我在本地网络上有一个设备,它提供以 HTML 格式读出的数据,并实时更新。到目前为止,我的 BeautifulSoup 和 URLLIB2 尝试解析这些数据都没有成功。
任何帮助将不胜感激。

这是源代码,圈出感兴趣的数据:

Image1

如果结果输出:

Image2

1
2
3
4
5
6
7
8
9
10
11
12
from bs4 import BeautifulSoup
import re
import urllib2
from urllib import urlopen
url = ‘http://192.168.1.2/index.html#home-view’
#___________________________________________________________________
usock = urllib2.urlopen(url)
data = usock.read()
usock.close()
soup = BeautifulSoup(data,“html.parser”)
result = soup.findAll(‘p’, {‘class’:‘gas-conc’})
print result

已解决!:感谢您的帮助。使用 Selenium,我能够痛苦地刮掉这些数据。但是我必须在源代码上使用 BS ‘beautify’ 功能并手动计算要拼接的字符。

  • 您能否以文本而不是图像的形式发布源代码?这对试图帮助的人来说更好
  • 顺便说一句,如果信息正在”实时”更改,可能是信息是由 JavaScript 生成的,而 requests 不加载 JS,你应该看看 selenium,我回答几天前的一个问题,如果你通过这种方式可能会有所帮助。
  • 请编辑您的问题并以文本形式包含源代码和输出。
  • 欢迎访问该站点:您可能需要阅读帮助中心、如何提问和最小可重复示例,并相应地重新表述您的问题。


我有 90% 的把握,除非你设法以某种方式呈现 Javascript,否则你不会得到这些数据。

查看这篇文章,了解如何实现这一点的更多信息。

简而言之,您可以使用:

  • selenium
  • PyQt5
  • 干刮

  • 来源:https://www.codenong.com/45382469/

    微信公众号
    手机浏览(小程序)

    Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

    Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

    Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9934.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
    0
    分享到:
    没有账号? 忘记密码?