在浏览器上使用xpath可以提取到想要的内容,但将xpath放入到代码中却返回空列表。将网页html抓下来后也没发现结构发生变化或者tbody之类的,于是采用正则表达式来提取内容。
想要提取的a.html:
代码如下:
with open("a.html","r") as r:
html = r.read()
pattern = re.compile(r"<span>#(.*?) in.+?<a href='(.*?)'>(.*?)</a>", re.S)
res = re.findall(pattern, html)
print(res)