Python爬虫实例一
来源:互联网 发布:淘宝快递自动改价模板 编辑:程序博客网 时间:2024/05/13 17:37
实例要求:
爬取小猪短租的房源链接以及每条房源链接的详情
详情爬取信息要求如下图:
爬取代码如下:
from bs4 import BeautifulSoupimport requestsimport timeurls = ['http://bj.xiaozhu.com/search-duanzufang-p{}-0/'.format(str(i)) for i in range(1,14,1)]def get_info(concrete_url): wb_data = requests.get(concrete_url) soup = BeautifulSoup(wb_data.text) first_imgs = soup.select('div.pho_show_big > div[valign="middle"] > img') titles = soup.select('div.pho_info > h4') addresses = soup.select('span.pr5') daymoneys = soup.select('div.day_l > span') hostimgs = soup.select('div.member_pic > a[target="_blank"] > img') sexes = soup.select('div.member_pic > div') hostnames=soup.select('a.lorder_name') for first_img, title, address, daymoney, hostimg, hostsex, hostname in zip(first_imgs,titles,addresses,daymoneys,hostimgs,sexes,hostnames): if hostsex.get('class')[0]=='member_ico1': hostsexone = '男' if hostsex.get('class')[0]=='member_ico': hostsexone = '女' if hostsex.get('class')[0]=='': hostsexone = ' 暂无' concreteinfo={ '房源图片':first_img.get('src'), '房屋标题': title.get_text(), '地址':address.get_text().strip(), '日租金':daymoney.get_text(), '房东照片':hostimg.get('src'), '房东性别':hostsexone, '房东名字':hostname.get_text() } print(concreteinfo)def get_urllist(url): wb_data = requests.get(url) soup = BeautifulSoup(wb_data.text) url_fangzis = soup.select('a.resule_img_a') for url_fangzi in url_fangzis: data={ 'url':url_fangzi.get('href') } get_info(data.get('url')) time.sleep(4)for url_one in urls: get_urllist(url_one)
爬取结果如下:
0 0
- Python爬虫实例一
- python爬虫慕课网实例(一)
- python实例---python爬虫
- python网络爬虫实例(一):爬取糗事百科
- Python爬虫爬取动态页面思路+实例(一)
- Python入门(一):爬虫基本结构&简单实例
- [mooc]python网络爬虫与信息提取(实例一)
- python 网络爬虫入门(一)———第一个python爬虫实例
- python 网络爬虫入门(一)———第一个python爬虫实例
- python爬虫实例
- Python 爬虫入门实例
- python爬虫小实例
- Python简单爬虫实例
- 一个python爬虫实例
- Python爬虫实例二
- Python爬虫实例三
- 简单Python爬虫实例
- Python 爬虫文字实例
- android_IntentService源码解析
- Handler(2)--主线程向自身消息队列发送消息
- 二:Quartz 中重要的家族成员
- Android客户端性能优化(魅族资深工程师毫无保留奉献)
- leetCode练习(25)
- Python爬虫实例一
- 三:Job 和 JobDetail 详细介绍
- Chrome开发者工具
- 四步轻松实现用Visio画UML类图
- Toast 与 Snakebar-->受够了瞎吐司
- java 8 Optional 解决NullPointerException
- hive数据库定义
- 四:Trigger
- iOS 学习笔记 视图切换