import requests from lxml import etreeimport reimport csvdef parser(url): head = { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36' } try: resp = requests.get(url, headers=head) 网页链接 = 'utf-8' html = 网页链接 pat = re.compile(r'<script.*?>.*?</script>|<style.*?>.*?</style>', re.S) sr_sc_txt = pat.sub('', html) print(sr_sc_txt) tree = etree.HTML(html) lis = tree.xpath("//*[@class='fl'][表情]") # print(lis) for li in lis: a_txt = li.xpath('./h3/text()')[0] save([a_txt]) print(a