• 51ll网产品信息保存为txt文件


    import requests
    from pyquery import PyQuery as pq
    
    url='http://www.51xxx.com/Try/index/p/3'
    headers={
        'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'
        }
    html=requests.get(url,headers=headers).text
    doc=pq(html)
    items=doc('.quan-body ul li').items()
    
    for item in items:
        pic=item.find('img').attr('src')
        title=item.find('.quan-t a').text()
        total_pro=item.find('.quan-yh i').text()
        back_price=item.find('.quan-qh-l em').text()
        price=item.find('.quan-qh-r s').text()
        people=item.find('.quan-yj em:nth-child(2)').text()
        with open('51pro.txt','a',encoding='utf-8') as f:
            f.write('
    '.join([pic,title,total_pro,back_price,price,people]))
            f.write('
    '+'#'*50+'
    ')
  • 相关阅读:
    tyvjP1078
    红黑树笔记
    红黑树插入代码学习
    tyvjP1082找朋友
    牛棚回声USACO OCT09 3RD
    每日参悟
    全排列学习
    学习1.2
    学习笔记1.1
    学习笔记1.3
  • 原文地址:https://www.cnblogs.com/chenxi188/p/10523783.html
Copyright © 2020-2023  润新知