这是我第一次尝试使用Python网页。
我有一台IP摄像头,可以通过HTTP将所有文件保存到HTML文档中。本质上,相机是自己的服务器,可以通过HTTP访问。服务器中的HTML非常基本。它只包含一个正文标记,其中包含此正文标记中的所有剪辑。文件如下:
MP_2018-04-23_11-14-04_60.mov
我想要列出/打印这些文件,而不需要与其关联的所有其他HTML。
import bs4 as bs
import urlib.request
sauce = urllib.request.urlopen('http://192.168.1.99/form/getStorageFileList').read()
soup = bs.BeautifulSoup(sauce,'lxml')
body = soup.body
for paragraph in body.find_all('b'):
print(body.text)
我在下面列出了一些屏幕截图,因为我收到的错误非常冗长。我基本上得到了:
属性错误:模块'html5lib.treebuilders'没有属性'_base'
有人会澄清并可能指出我正确的方向吗?
usr/lib/python3/dist-packages/bs4/builder/_html5lib.py in <module>()
68
69
---> 70 class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder):
71
72 def __init__(self, soup, namespaceHTMLElements):
AttributeError: module 'html5lib.treebuilders' has no attribute '_base'
答案 0 :(得分:0)
您的脚本中有一些错误。不过没什么大不了的。另外,使用Requests库可能会带来更多好处。那这样的事呢?
from bs4 import BeautifulSoup as bs
import requests
sauce = requests.get('http://192.168.1.99/form/getStorageFileList')
page = sauce.text #Converted page to text
soup = bs(page,'html.parser') #Changed to 'html.parser'
body = soup.body('body') #Added the 'body' tag
for paragraph in body.find_all('b'):
print(paragraph.text) #Grabbed the iterated items & converted them to text
让我知道这是否是您想要的东西。