要先将源码etree
代码语言:javascript复制html = requests.get(=url=headers).text
html = etree.HTML(html)
html = etree.tostring(html=).decode()
html.xpath('/html/body/div/ul/li/a[@href="link2.html"]/text()')
或将html.text转换为选择器对象
代码语言:javascript复制import parsel
html = parsel.Selector(html_str)
url = html.xpath('//div').extract()