Python爬虫1----房源信息
来源:互联网 发布:电子地图数据库 编辑:程序博客网 时间:2024/04/26 05:17
任务描述
爬取300个房源信息,每页具体信息如下
Python代码
#-*- coding: UTF-8 -*-# 20170217:work wellfrom bs4 import BeautifulSoupimport requests# 形成小猪主页上前10页的网址urls = ['http://bj.xiaozhu.com/search-duanzufang-p{}-0/'.format(str(i)) for i in range(1, 11, 1)]# 性别不同,标签的class属性内容不同,通过这个差异区分房东性别def get_lorder_sex(class_name): if class_name == ['member_ico']: return '男' elif class_name == ['member_ico1']: return '女'#对每一页上的具体信息进行解析def get_attar(url): web_data = requests.get(url) soup = BeautifulSoup(web_data.text, 'lxml') titles = soup.select('div.pho_info > h4 > em') locations = soup.select('div.pho_info > p > span') prices = soup.select('div.day_l > span') images = soup.select('div.pho_show_big > div > img') lorder_names = soup.select('div.w_240 > h6 > a') lorder_images = soup.select('div.member_pic > a > img') lorder_genders = soup.select('div.member_pic > div') for title, location, price, image, lorder_name, lorder_image, gender in zip(titles, locations, prices, images, lorder_names, lorder_images, lorder_genders): data = { 'title': title.get_text(), 'location': location.get_text(), 'price': price.get_text(), 'image': image.get('src'), 'lorder_name': lorder_name.get_text(), 'lorder_image': lorder_image.get('src'), "gender": get_lorder_sex(gender.get("class")) } print data#10个主页中,每一个主页又有很多小页:上面记录了待租房的具体信息for url in urls: web_data = requests.get(url) soup = BeautifulSoup(web_data.text, 'lxml') url_links = soup.select('a.resule_img_a') for url_link in url_links: get_attar(url_link.get('href'))
结果展示
这里仅截取其中两个房源信息
不足之处
Pycharm的控制台中,对中文汉字,只能显示其字符编码,未能显示中文
0 0
- Python爬虫1----房源信息
- 利用python爬取我爱我家租赁房源信息
- 链接网房源信息redis分布式爬虫及数据可视化-武汉市
- 3.python开源——scrapy爬虫获取周边新楼盘房源(CSDN)
- 房源
- 自如网房源释放自动提醒爬虫
- 一、如何爬取链家网页房源信息
- 诸葛找房房源信息爬取
- Python爬虫爬取美剧网站信息
- python爬虫爬取拉勾网职业信息
- python爬虫爬取链家二手房信息
- 【Python爬虫】了解网站信息
- 【MOOC】Python网络爬虫与信息提取-北京理工大学-part 1
- python爬虫入门:1--爬取维基百科词条信息
- 玩转Python爬虫与信息获取(1)
- Python 网络爬虫获取豆瓣信息
- python 爬虫之校园招聘信息
- python 爬虫获取网站信息(一)
- Qt 调试Caffe
- 58到家数据库30条军规解读
- hadoop入门(二)
- react构建淘票票webapp,及react与vue的简单比较。
- 解决OKHttp不能自动缓存header cookies 里的 sessionid
- Python爬虫1----房源信息
- Nsight 调试 Caffe
- 我的博客即将入驻“云栖社区”,诚邀技术同仁一同入驻。
- seelog 日志滚动配置
- 再议数据库军规
- ADO MoveFirst, MoveLast, MoveNext, 与 MovePrevious 方法
- Win10下安装Cisco VPN Client终极解决方法
- flannel + etcd + docker 环境中双网卡问题
- Android记录官方文档系列(3):Fragment(中)