我在解析信息以检索 HTML 文档中使用的 html 和元标记列表以及每个标记在文档中出现的次数时遇到问题。
因此,例如,如果我有以下 html 文档
<head>
<a href="example.com">example1</a>
<a href="example.com">example2</a>
<a href="example.com">example3</a>
</head>
然后你会得到一个类似的列表
head tag =1
a tag =3
我正在尝试用 php 来做这件事,如果有人能给我一个很好的起点的话。
编辑:我正在尝试复制类似以下 python 代码但使用 php
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print "Encountered a start tag:", tag
def handle_endtag(self, tag):
print "Encountered an end tag :", tag
def handle_data(self, data):
print "Encountered some data :", data