我正在使用Windows,并尝试在python上安装html5lib-0.90库
C:\>python C:\Users\Junior\Downloads\Python\html5lib-0.90\setup.py install
Traceback (most recent call last):
File "C:\Users\Junior\Downloads\Python\html5lib-0.90\setup.py", line 36, in <module>
for name in os.listdir(os.path.join('src','html5lib'))
WindowsError: [Error 3] The system cannot find the path specified: 'src\\html5lib/*.*'
Run Code Online (Sandbox Code Playgroud)
是否可以在Windows上安装此库?
有教程或安装手册吗?
我试图从BeautifulSoup中解脱出来,我喜欢但似乎(积极地)不受支持.我正在尝试使用html5lib和lxml,但我似乎无法弄清楚如何使用"find"和"findall"运算符.
通过查看html5lib的文档,我想出了一个测试程序:
import cStringIO
f = cStringIO.StringIO()
f.write("""
<html>
<body>
<table>
<tr>
<td>one</td>
<td>1</td>
</tr>
<tr>
<td>two</td>
<td>2</td
</tr>
</table>
</body>
</html>
""")
f.seek(0)
import html5lib
from html5lib import treebuilders
from lxml import etree # why?
parser = html5lib.HTMLParser(tree=treebuilders.getTreeBuilder("lxml"))
etree_document = parser.parse(f)
root = etree_document.getroot()
root.find(".//tr")
Run Code Online (Sandbox Code Playgroud)
但是这会返回None.我注意到,如果我这样做,etree.tostring(root)我会收回所有数据,但我的所有标签都以html(例如<html:table>)开头.但root.find(".//html:tr")抛出一个KeyError.
有人能让我回到正轨吗?
如何<body>通过html5lib在 Python 中使用来获取元素的内容?
示例输入数据: <html><head></head><body>xxx<b>yyy</b></hr></body></html>
预期输出: xxx<b>yyy</b></hr>
即使 HTML 损坏(未关闭的标签,...),它也应该可以工作。
我正在使用Python和Beautifulsoup来解析HTML-Data并从RSS-Feeds中获取p-tags.但是,一些URL会导致问题,因为解析的汤对象不包括文档的所有节点.
例如,我试图解析http://feeds.chicagotribune.com/~r/ChicagoBreakingNews/~3/T2Zg3dk4L88/story01.htm
但是在将解析后的对象与页面源代码进行比较后,我注意到之后的所有节点ul class="nextgen-left"都丢失了.
以下是我解析文档的方法:
from bs4 import BeautifulSoup as bs
url = 'http://feeds.chicagotribune.com/~r/ChicagoBreakingNews/~3/T2Zg3dk4L88/story01.htm'
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
request = urllib2.Request(url)
response = opener.open(request)
soup = bs(response,'lxml')
print soup
Run Code Online (Sandbox Code Playgroud)