爬取一首唐诗
作者:互联网
from lxml import etree import requests # 爬取一首唐诗 hercx={ 'User-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.25' } xcvb=requests.get('https://so.gushiwen.cn/shiwenv_478043ea449a.aspx',headers=hercx).text '爬取一首古诗' html=etree.HTML(xcvb) '标头的xpth的' roto=html.xpath('//*[@id="sonsyuanwen"]/div[1]/h1/text()') "作者的xpth" roto1=html.xpath('//*[@id="sonsyuanwen"]/div[1]/p/a[1]/text()') '诗句' textuio=html.xpath('/html/body/div[2]/div[1]/div[2]/div[1]/div[2]/text()') for i in textuio: print(str(i).replace(' ',''))
标签:xpath,唐诗,text,爬取,html,一首,hercx,div 来源: https://www.cnblogs.com/xxh12/p/16673877.html