python爬取链家租房之获取房屋页面的详细信息(房名,地址,房价,面积,url)

__author__ = 'Lee'
from bs4 import BeautifulSoup
import requests
import time
url = 'https://bj.lianjia.com/zufang/101101613377.html'
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
}
web_data = requests.get(url,headers=headers)
soup = BeautifulSoup(web_data.text,'lxml')
title = soup.title.text #房名
address = soup.select('div.zf-room > p > a')[0].text  #地址
price = soup.select(' div.price > span.total')[0].text + '元'
area = (soup.select('div.zf-room > p ')[0].text).split(':')[-1]
home_url = url
print({'title':title ,
       'address':address,
       'price':price,
       'area':area,
       'home_url':home_url
       })

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券