0
点赞
收藏
分享

微信扫一扫

python爬虫学习-xpath解析

小编 2022-01-16 阅读 133
import requests
from lxml import etree

if __name__ == '__main__':
    url = 'https://www.zbj.com/search/f/?kw=sass'
    res = requests.get(url=url)
    #x=res.text.encode('gbk','ignore')#转换编码方式
    #print(x.decode('gbk'))
    html=etree.HTML(res.text)
    divs=html.xpath('/html/body/div[6]/div/div/div[2]/div[5]/div[1]/div')
    for div in divs:
        price=div.xpath('./div/div/a[2]/div[2]/div[1]/span[1]/text()')[0].strip("¥")
        title = div.xpath('./div/div/a[2]/div[2]/div[2]/p/text()')
        print(price)
```python
在这里插入代码片

举报

相关推荐

0 条评论