Can';t使用Python解析HTML
我使用HTMLPasser库解析html代码。当我重写handle\u starttag方法时,我只检索带有“root”元素的片段。我需要从表中提取一些链接。我拆分html字符串并尝试解析片段,但结果相同。当我尝试解析以下片段时:Can';t使用Python解析HTML,python,Python,我使用HTMLPasser库解析html代码。当我重写handle\u starttag方法时,我只检索带有“root”元素的片段。我需要从表中提取一些链接。我拆分html字符串并尝试解析片段,但结果相同。当我尝试解析以下片段时: <td class="lineItemMainInfo" width="100%"> <div class="lineItemGroup"> <div><span class="small prod
<td class="lineItemMainInfo" width="100%">
<div class="lineItemGroup">
<div><span class="small productTitle"><strong>
<a rel="nofollow" href="/dp/B007R5YFS4/ref=wl_fv/191-7812654-8275300?_encoding=UTF8&colid=1VII2NY76H4UZ&coliid=I17H6RZSYMY3L1">
Amazon Kindle Paperwhite Leather Cover, Onyx Black (does not fit Kindle or Kindle Touch)
</a>
</strong></span></div>
<div class=lineItemPart style="margin-top: 40px;"><span class=wlPriceBold>$39.99</span></div>
<div style="margin-top: 40px;"><a href="/gp/item-dispatch/ref=cm_wl_addtocart_v/191-7812654-8275300?ie=UTF8&colid=1VII2NY76H4UZ&coliid=I17H6RZSYMY3L1&offeringID.1=XPVNq%252BOcYJUJX1KIbumcWx6ws9PGgJa3gAVhZKZdE0ZWN%252FAq6rL2CoBnw4sUpGte0oDqJjGH15dpME1xUYMI1yg%252BO5y7fw2cpA7RmRZJHNIZw09fS2l4OQ%253D%253D&quantity.1=1&registryID.1=1VII2NY76H4UZ&registryItemID.1=I17H6RZSYMY3L1&session-id=191-7812654-8275300&signInToHUC=0&submit.addToCart=1"><span class="swSprite s_add2CartSm " border="0" vspace="0" hspace="0"style="vertical-align:middle;margin-bottom:2px;" alt="Add to Cart"></span></a></div>
</div>
</td>
$39.99
我只接收td标记,没有任何嵌套标记。
有人有这个问题吗 我可以谦恭地建议更换HTMLPasser-?我相信它将帮助您快速解决问题。提示:如果您正在进行网页抓取(或者通常需要快速访问页面中的各种元素),我强烈建议您使用BeautifulSoup库(特别是如果您必须处理“真实世界”,丑陋的HTML)。感谢您的推荐!美丽的群像太棒了。