您好,登錄后才能下訂單哦!
這篇文章主要介紹Python如何爬取房天下新樓盤信息,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
前言
import requests from lxml import etree import re from bs4 import BeautifulSoup import openpyxl import csv def get_price(): headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0', 'Refrer': 'https://ganzhou.newhouse.fang.com/house/s/b9{}/', } for i in range(1, 10): url = "https://ganzhou.newhouse.fang.com/house/s/b9{}/".format(str(i)) response = requests.get(url, headers=headers) if response.status_code == 200: xml = etree.HTML(response.content.decode('gbk')) name = xml.xpath('//div[@class="nl_con clearfix"]//div[@class="nlc_details"]//a[@data-yd=""]//text()') for index in range(len(name)): name[index] = name[index].strip() address = xml.xpath('//div[@class="nl_con clearfix"]//div[@class="nlc_details"]//div[@class="address"]/a/text()') for index in range(len(address)): address[index] = address[index].strip() price = xml.xpath('//div[@class="nl_con clearfix"]//div[@class="nlc_details"]//div[@class="nhouse_price"]/span/text()') for index in range(len(price)): price[index] = price[index].strip() with open('贛州房?jī)r(jià).csv', 'w') as f: writer = csv.writer(f) writer.writerows(zip(name, price, address)) f.close() if __name__ == '__main__': get_price()
以上是“Python如何爬取房天下新樓盤信息”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。