python xpath

import requests
from lxml import etree
# //ul[@id = "showImg"]/li/a/img/@src

text = requests.get('your url').text
# html = etree.HTML(text)
# result = etree.tostring(html)
# print(result.decode('UTF-8'))
html = etree.HTML(text)
# '//'表示获取当前节点子孙节点,'*'表示所有节点,'//*'表示获取当前节点下所有节点
result = html.xpath('//ul[@id = "showImg"]/li/a/img/@src')

for i in result:
    print(i)

传送门
posted @ 2020-01-21 17:29  酷酷的城池  阅读(106)  评论(0编辑  收藏  举报