• BeautifulSoup随记


    
    
    
    
    

    soup = BeautifulSoup(html, 'html.parser') # <img alt="五洋运河人家" class="lj-lazy" data-original="https://ke-image.ljcdn.com/hdic-resblock/e4262fc4-3e37-4d92-aab5-5479a98bd6cf.jpg.232x174.jpg" src="https://s1.ljcdn.com/pegasus/redskull/images/common/blank.gif?_v=20210723191610" title="五洋运河人家"/> # print(soup.select('a img')[0]['alt']) img=soup.select('a img')[0] print(img['title'],img['src']) //五洋运河人家 https://s1.ljcdn.com/pegasus/redskull/images/common/blank.gif?_v=20210723191610

    info
    =soup.select('div[class="info"]') title=info[0].select('div[class="title"] > a') print(title[0]['title']) 五洋运河人家

    houseInfo
    =soup.select('div[class="houseInfo"] > a') print(houseInfo[0]['href'], houseInfo[0].get_text()) http://hz.zu.ke.com/zufang/c1811043636979/ 9套正在出租
    positionInfo
    =soup.select('div[class="positionInfo"] > a') for i in positionInfo: print(i['href'], i.get_text())
    https://hz.ke.com/xiaoqu/gongshu/ 拱墅
    https://hz.ke.com/xiaoqu/gongchenqiao/ 拱宸桥




     

    tagList=soup.select('div[class="tagList"] > span') 
    for i in tagList:
    print(i.get_text())
    近地铁地铁5号线拱宸桥东站





  • 相关阅读:
    VUE入门
    搭建内网穿透服务
    nacos集群配置安装
    jenkins入门
    Linux系统管理与自动化运维
    SVN
    JAR包启动
    服务器rm -rf 恢复案例 好文章
    docker入门到放弃
    CentOS7安装图形界面及报错处理
  • 原文地址:https://www.cnblogs.com/yansc/p/15058022.html
Copyright © 2020-2023  润新知