日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python爬虫爬取58同城北京品牌公寓租房信息

發布時間:2024/5/14 python 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python爬虫爬取58同城北京品牌公寓租房信息 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
from bs4 import BeautifulSoup from urllib.parse import urljoin import requests import csvurl = "http://bj.58.com/pinpaigongyu/pn/{page}/?minprice=2000_4000"#已完成的頁數序號,初時為0 page = 0csv_file = open("rent.csv","wb") csv_writer = csv.writer(csv_file, delimiter=',')while True:page += 1print ("fetch: ", url.format(page=page))response = requests.get(url.format(page=page))html = BeautifulSoup(response.text,"lxml")house_list = html.select(".list > li")# 循環在讀不到新的房源時結束if not house_list:if sign == 3:print(" 已經度曲完畢")breakelse:print(" 出現獲取不到列表,再次嘗試")sign += 1time.sleep(random.randint(1,3))continuesign = 0for house in house_list:house_title =str(house.select("h2")[0].string)house_url = urljoin(url, house.select("a")[0]["href"])house_info_list = house_title.split()# 如果第二列是公寓名則取第一列作為地址if "公寓" in house_info_list[1] or "青年社區" in house_info_list[1]:house_location = house_info_list[0].split("]")[1]else:house_location = house_info_list[1]house_money = house.select(".money")[0].select("b")[0].string.encode("utf8")csv_writer.writerow([house_title, house_location, house_money, house_url])csv_file.close()

總結

以上是生活随笔為你收集整理的python爬虫爬取58同城北京品牌公寓租房信息的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。