from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
def __init__(self, *args, **kw):
super().__init__(*args, **kw)
self.archorlist = []
def handle_starttag(self, tag, attrs):
if tag == 'a' and 'href' in attrs:
self.anchorlist.append(attrs['href'])
anchorlist
属性是^{另一方面,python3中的} 。它不具有
html.parser
模块在python2中被称为^{anchorlist
属性。在您可以通过监听开始标记事件来模拟该属性,对于任何
a
标记,请将href
属性(如果存在)添加到列表中,以生成相同的列表:或者,使用一个更友好的API,比如BeautifulSoup来收集链接锚。在
相关问题 更多 >
编程相关推荐