爬取一首唐诗

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(' ',''))

 

posted @ 2022-09-09 20:13  python,菜鸟  阅读(40)  评论(0)    收藏  举报