Python爬蟲
python爬取鏈家上面的北京租房資訊
1.導包:
import requests
from bs4 import BeautifulSoup
2.獲取url頁面下的內容,返回soup物件:
def get_page(url):
responce = requests.get(url)
soup = BeautifulSoup(responce.text,'lxml')
return soup
3.封裝成函式,作用是獲取列表頁下面的所有租房頁面的連結,返回一個連結列表:
def get_links(link_url):
soup = get_page(link_url)
content_list = soup.find('div', class_="content__list")
links_div = content_list.find_all('div', class_="content__list--item")
links = []
for div in links_div:
tmp = div.find('a')
if tmp != -1:
pass
links.append(div.a.get('href'))
return links
4.使用get_links(llink_url)函式獲取鏈家首頁的所有租房頁面的連結
url = 'https://bj.lianjia.com/zufang/'
get_links(url)
5.獲取租房頁面的房屋資訊
house_url='https://bj.lianjia.com/zufang/BJ2360825321093611520.html?nav=0&unique_id=ee73be87-3abd-477e-af89-a3f320eda277zufang1602224217718'
soup=get_page(house_url)
price=int(soup.find('div',class_='content__aside--title').span.text)
good_house=soup.find('p',class_='content__aside--tags').text.replace('\n', '')
content__aside__list=soup.find('ul',class_='content__aside__list')
content__aside__list = content__aside__list.find_all('li')
house_way=content__aside__list[0].text[5:]
house_type=content__aside__list[1].text[5:]
house_floor=content__aside__list[2].text[5:][:-2]
riskwarning=content__aside__list[3].text[5:]
info = {
'房屋價格':price,
'必看好房':good_house,
'租賃方式':house_way,
'房屋型別':house_type,
'朝向樓層':house_floor,
'風險提示':riskwarning
}
info
相關文章
- 【Python學習】爬蟲爬蟲爬蟲爬蟲~Python爬蟲
- 【python爬蟲】python爬蟲demoPython爬蟲
- python爬蟲---網頁爬蟲,圖片爬蟲,文章爬蟲,Python爬蟲爬取新聞網站新聞Python爬蟲網頁網站
- python就是爬蟲嗎-python就是爬蟲嗎Python爬蟲
- python 爬蟲Python爬蟲
- python爬蟲初探--第一個python爬蟲專案Python爬蟲
- Python爬蟲教程-01-爬蟲介紹Python爬蟲
- Java爬蟲與Python爬蟲的區別?Java爬蟲Python
- Python asyncio 爬蟲Python爬蟲
- python爬蟲2Python爬蟲
- Python爬蟲——XPathPython爬蟲
- Python 爬蟲系列Python爬蟲
- Python爬蟲-xpathPython爬蟲
- Python爬蟲--2Python爬蟲
- python網路爬蟲_Python爬蟲:30個小時搞定Python網路爬蟲視訊教程Python爬蟲
- 什麼是Python爬蟲?python爬蟲入門難嗎?Python爬蟲
- python爬蟲是什麼?學習python爬蟲難嗎Python爬蟲
- 什麼是Python爬蟲?Python爬蟲常用框架有哪些?Python爬蟲框架
- 【Python爬蟲9】Python網路爬蟲例項實戰Python爬蟲
- Python爬蟲入門教程 50-100 Python3爬蟲爬取VIP視訊-Python爬蟲6操作Python爬蟲
- 【python--爬蟲】彼岸圖網高清桌布爬蟲Python爬蟲
- 什麼是爬蟲?Python爬蟲框架有哪些?爬蟲Python框架
- 【爬蟲】python爬蟲從入門到放棄爬蟲Python
- Python爬蟲之路-chrome在爬蟲中的使用Python爬蟲Chrome
- Python爬蟲與Java爬蟲有何區別?Python爬蟲Java
- python爬蟲實戰,爬蟲之路,永無止境Python爬蟲
- Python爬蟲(1.爬蟲的基本概念)Python爬蟲
- 圖靈樣書爬蟲 - Python 爬蟲實戰圖靈爬蟲Python
- 不踩坑的Python爬蟲:Python爬蟲開發與專案實戰,從爬蟲入門 PythonPython爬蟲
- python爬蟲-33個Python爬蟲專案實戰(推薦)Python爬蟲
- Python爬蟲可以幹什麼?Python爬蟲有什麼用?Python爬蟲
- Python分散式爬蟲(三) - 爬蟲基礎知識Python分散式爬蟲
- python網路爬蟲(14)使用Scrapy搭建爬蟲框架Python爬蟲框架
- Python爬蟲教程-34-分散式爬蟲介紹Python爬蟲分散式
- Python爬蟲教程-30-Scrapy 爬蟲框架介紹Python爬蟲框架
- Python爬蟲之路-爬蟲基礎知識(理論)Python爬蟲
- Python爬蟲之路-selenium在爬蟲中的使用Python爬蟲
- Python爬蟲和java爬蟲哪個效率高Python爬蟲Java