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号线拱宸桥东站