大家好,关于楼盘网站系统源码分享很多朋友都还不太明白,不过没关系,因为今天小编就来为大家分享关于楼盘网是做什么的的知识点,相信应该可以解决大家的一些困惑和问题,如果碰巧可以解决您的问题,还望关注下本站哦,希望对各位有所帮助!
importrequests导入csv库,用于输出csv文件
frombs4importBeautifulSoup添加请求头,模拟浏览器运行
header={‘user-agent’:’Mozilla/5.0(WindowsNT6.1)AppleWebKit/537.36(KHTML,likeGecko)Chrome/61.0.3163.79Safari/537.36Maxthon/5.2.6.1000′}
给出要爬取的页面链接
link=’https://fz.anjuke.com/sale/p’+str(i)+’/发送请求,获得响应体,r.text是响应体也是网页的html代码
r=requests.get(link,headers=header)
对获得的响应体(网页源代码)进行解析,解析格式为lxml
soup=BeautifulSoup(r.text,’lxml’)
建立csv文件
withopen(‘test.csv’,’a’,newline=”,encoding=’utf-8-sig’)ascsvfile:
w=csv.writer(csvfile)
w.writerow((‘标题’,’价格’,’均价’,’面积’,’楼层’))
forhouseinhouse_list:
temp=[]
name=house.find(‘div’,class_=’house-title’).a.text.strip()
price=house.find(‘div’,class_=’pro-price’).contents[1].text.strip()
price_ave=house.find(‘div’,class_=’pro-price’).contents[2].text.strip()
area=house.find(‘div’,class_=’details-item’).span.text
floor=house.find(‘div’,class_=’details-item’).contents[5].text
temp=[name,price,price_ave,area,floor]
print(temp)
#按行写入以上解析数据
文章到此结束,如果本次分享的楼盘网站系统源码分享和楼盘网是做什么的的问题解决了您的问题,那么我们由衷的感到高兴!
