爬取上海链家二手房信息 源代码共享
最编程
2024-06-28 21:36:01
...
'''
def down_load(page):
for i in range(1,page+1):
if i==1:
url = 'https://cm.lianjia.com/ershoufang/'
else:
url = 'https://cm.lianjia.com/ershoufang/pg'+str(i)+'/'
headers = {'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
}
response = requests.get(url=url,headers=headers)
response.encoding = 'utf-8'
tree = etree.HTML(response.text)
# print(response.text)
mark_list = tree.xpath('//ul[@class="sellListContent"]//div[@class="info clear"]//div[@class="title"]//a//text()')
address_list = tree.xpath('//ul[@class="sellListContent"]//div[@class="flood"]//div//a[1]//text()')
introduce_list = tree.xpath('//ul[@class="sellListContent"]//div[@class="address"]//div//text()')
Sum_price_list = tree.xpath('//div[@class="priceInfo"]//div[@class="totalPrice totalPrice2"]//span//text()')
avg_price_list = tree.xpath('//div[@class="priceInfo"]//div[@class="unitPrice"]//span//text()')
# print(avg_price_list)
for i in range(len(mark_list)):
mark = mark_list[i] # 房子的介绍
address = address_list[i] # 房子的地址
introduce = introduce_list[i].split('|')
sum_price = Sum_price_list[i]+'万' # 房子的总价
avg_price = avg_price_list[i] # 房子的均价
unit_type = introduce[0] # 房子的面积 几室几厅
acreage = introduce[1] # 房子的面积
decorate_type = introduce[2] # 装修
flood = introduce[3] #楼层
try:
build_type = introduce[4] #样式
except:
build_type='无数据'
# dit = {
# '介绍':mark,
# '地址':address,
# '户型':unit_type,
# '面积':acreage,
# '装修':decorate_type,
# '楼层':flood,
# '样式':build_type,
# '总价':sum_price,
# '均价':avg_price,
# }
csv_writer.writerow([mark,address,unit_type,acreage,decorate_type,flood,build_type,sum_price,avg_price])
def down_load(page):
for i in range(1,page+1):
if i==1:
url = 'https://cm.lianjia.com/ershoufang/'
else:
url = 'https://cm.lianjia.com/ershoufang/pg'+str(i)+'/'
headers = {'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
}
response = requests.get(url=url,headers=headers)
response.encoding = 'utf-8'
tree = etree.HTML(response.text)
# print(response.text)
mark_list = tree.xpath('//ul[@class="sellListContent"]//div[@class="info clear"]//div[@class="title"]//a//text()')
address_list = tree.xpath('//ul[@class="sellListContent"]//div[@class="flood"]//div//a[1]//text()')
introduce_list = tree.xpath('//ul[@class="sellListContent"]//div[@class="address"]//div//text()')
Sum_price_list = tree.xpath('//div[@class="priceInfo"]//div[@class="totalPrice totalPrice2"]//span//text()')
avg_price_list = tree.xpath('//div[@class="priceInfo"]//div[@class="unitPrice"]//span//text()')
# print(avg_price_list)
for i in range(len(mark_list)):
mark = mark_list[i] # 房子的介绍
address = address_list[i] # 房子的地址
introduce = introduce_list[i].split('|')
sum_price = Sum_price_list[i]+'万' # 房子的总价
avg_price = avg_price_list[i] # 房子的均价
unit_type = introduce[0] # 房子的面积 几室几厅
acreage = introduce[1] # 房子的面积
decorate_type = introduce[2] # 装修
flood = introduce[3] #楼层
try:
build_type = introduce[4] #样式
except:
build_type='无数据'
# dit = {
# '介绍':mark,
# '地址':address,
# '户型':unit_type,
# '面积':acreage,
# '装修':decorate_type,
# '楼层':flood,
# '样式':build_type,
# '总价':sum_price,
# '均价':avg_price,
# }
csv_writer.writerow([mark,address,unit_type,acreage,decorate_type,flood,build_type,sum_price,avg_price])
推荐阅读
-
抓取上海链家的二手房数据信息,并使用 mysql 保存。
-
爬取上海链家二手房信息 源代码共享
-
使用 python 抓取链家上海二手房信息的案例
-
爬取链家数据,用散点图分析武汉二手房价
-
爬取链家北京城二手房链号
-
Python 爬虫实践:爬取链家网二手房数据
-
房产中介遭遇寒冬,链家转型之路任重道远?-房产中介寒冬到来,链家急切求生? “想到了市场会变坏,但没有想到会来得这么快,逼着我们转型。”这是2017年下半年,已经处于转型当中的搜房网董事长莫天全说过的一句话,这句话反映了链家所在的房产交易市场近两年来并不好过。 2017年链家在北京和上海的二手房市场陷入低谷。链家在北京二手房成交量同比下滑51%,在上海,链家2017年月均交易量只有一万套左右。上海北京一直是支撑链家房产交易量的两个重点城市,这两个城市交易量呈现下降,很大程度上说明其它地方可能也不好过。据业内人士估算,二手房市场月成交1.5万套才是盈亏的分水岭,并且规模越大,亏损得越多。 事实上,链家所在的房产中介行业,从2016年开始,受国家不断出台的房产调控政策,比如“去库存”、“棚改”、“房产税收”等影响,行业内各个房产中介开始出现裁员收缩、关店、交易量下降等现象。这些现象虽然都是正常的市场反应,不必过慌,但对于链家而言,每少一家线下店,每少一名经纪人,可能都是不小的打击。 链家闫觅曾说:“目前如何提高运营效率是长租公寓运营商面临的一大难题,推出贝壳找房一方面能给加入者带来流量红利,一方面为参与者带来业务升级,提升房产交易效率。”如此看来,加入贝壳找房好处颇多。不过天下毕竟没有免费的午餐,链家如此让利给入局者,总得有一个说得过去理由。其实,长期以上述模式走下去的贝壳找房,能帮助链家实现真房源数据的维护。如果是出于这样的目的,那么推出贝壳找房可以看成是链家在行业压力下寻求自救的举措。 链家拥抱第三方平台,真实房源数据是终极目标? 要问链家的核心资源在哪里,那么毫无疑问,全国约7000万套真房源数据是链家的核心所在,这是链家生态系统得以运转的血液,也是链家在对外讲话当中,常常提到的事情。从链家的官网简介当中可以看出,链家已经涉及到房产交易服务、大数据处理、资产管理等业务,这些业务大多数是建立在房源数据交易的基础之上。因而如果房源数据出现了问题,那么其产生的后果可想而知。 真房源数据甄别的主体可以来源于两方面,要么亲力亲为,要么让别人去帮你完成甄别。对于主打真房源的链家而言,线下门店是链家真房源的有利保障,要知道从链家一开始提出真房源理念后,其线下门店就开始马不停蹄地扩张,所以即使当行业虚假房源信息泛滥的时候,链家也能有底气提出“真房源”理念。而随着线下门店数量的减少,在2017年8月,链家开始和拥有1800家门店、覆盖54座城市的21世纪中国不动产,就双方加盟合作事宜进行谈判,而且在今年1月份,链家重启德佑品牌,进行加盟模式的布局,可见链家对于加盟模式的重视程度。 目前链家的加盟模式可以分为轻加盟和重度加盟。对于一些平台,例如对乐乎、同创、城家、湾流等品牌公寓,链家采取的是“品质联盟”的形式,换个角度可以理解为轻加盟模式,大家签个正品协议,然后你把你的房源挂到我的平台上。而对于个人加盟甚至是中小中介平台,链家一般采用重度加盟模式,这种模式会从人员的招聘、培训、管理等环节对加入者实行全程干预。 例如链家在2017年下半年,鼓励内部员工自主加盟到链家网当中,加盟者需承担门店的一切费用。同时向链家支付10%的营业额作为加盟费,而加盟者的员工由链家培训,以确保加盟模式跟自己的直营模式在服务上做到无差异。这些事例都在一定程度上反映了链家想找最省钱的真房源确认途径。 其实,链家很清楚,重度垂直门店模式会占用大量的资金,在业务不景气的时候,易造成资金周转困难,不过链家也明白,线下门店是链家开疆扩土的前沿阵地,是真房源数据的最基础来源。因而在线下门店处于收缩的时候,以第三方平台确认真房源的打法,自然而然会成为链家现今的最佳选择。 匆忙布局,链家转型之路并不平坦
-
python3 爬行器教学,爬取链家二手房(底层源代码) // 更新源代码
-
Python 爬虫--上海链家二手房数据爬取与可视化分析
-
履带式实例:链家二手房数据爬取