python找豆瓣房源
python 用豆瓣找北京房源
import requestsfrom bs4 import BeautifulSoupimport openpyxlheaders={'origin':'https://www.douban.com','referer':'https://www.douban.com/group/beijingzufang/','User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'}
list_all = []for x in range(10):res= requests.get('https://www.douban.com/group/beijingzufang/discussion?start=x*25',headers=headers)bs= BeautifulSoup(res.text,'html.parser')list= bs.find_all('td',class_='title')for i in list:tag= i.find('a')name = tag['title']URL = tag['href']list_all.append([name,URL])web=openpyxl.Workbook()sheet = web.activesheet.title = '租房信息'for i in list_all:sheet.append(i)web.save(r'd:\豆瓣租房信息.xlsx')
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
