某短租平台房屋信息爬取

观察页面
数据
元素
Class
全部文字信息
Div
div._qlq27g
类型
Div
div._1etkxf1
标题
Div
div._qrfr9x5
评分
Span
Span._1clmxfj
价格
Div
div._qg0ydb
当前页所有房源信息
Div
div._fhph4u
 
使用selenium模块
连续爬取100个房屋信息
import time
from selenium import webdriver
driver = webdriver.Chrome()

for j in range(0,101,20):
    #url = "https://www.airbnb.cn/s/%E4%B8%8A%E6%B5%B7/homes?items_offset=%d" % (j)
    driver.get(url="https://www.airbnb.cn/s/上海/homes?items_offset=%d" % (j))
    #driver.get(url=f"https://www.airbnb.cn/s/%E4%B8%8A%E6%B5%B7/homes?items_offset={j}")
    time.sleep(3)#等待页面完全加载
    title = driver.find_elements_by_css_selector('div._qrfr9x5')  #所有标题
    tag = driver.find_elements_by_css_selector('div._1etkxf1')    #所有类型
    age = driver.find_elements_by_css_selector('span._1clmxfj')   #所有评分
    price = driver.find_elements_by_css_selector('div._qg0ydb')   #所有价格
    for i in range(0,19):
        print(title[i].text,tag[i].text,age[i].text,price[i].text.replace('\n','-'))
输出
<PROVENCE>武康路五原路老洋房,带露台,近7号线|10号线|1号线常熟路、上海图书馆地铁站 整套公寓 · 1室1.5卫1床 5.0分 · 9条评论 价格-¥599-每晚-盛夏特惠 9.5 折
乌鲁木齐中路静安寺复式花园洋房 长租优惠 整间LOFT · 1室1卫1床 4.9分 · 177条评论 价格-¥200-每晚
[玉兰]绍兴路百年洋房 梧桐树下的 电影小屋 近田子坊/iapm 有猫可撸 独立房间 · 1室1卫1床 4.8分 · 5条评论 价格-¥326-每晚-周租优惠

PS:

想转换为bs4解析并提取
soup = BesutifulSoup(driver.page_source,'lxml')

 

posted @ 2022-02-28 19:10  JKding233  阅读(61)  评论(0)    收藏  举报