最近应一个老铁的要求,人家是搞房产的,所以就写了这个二手房的爬虫,因为初版,所以比较简单,有能力的老铁可用进行扩展。

import requests
import os
 
from bs4 import BeautifulSoup
 
 
 
class GanJi():
    """docstring for GanJi"""
 
    def __init__(self):
        super(GanJi, self).__init__()
 
    def get(self,url):
 
        user_agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36'
        headers    = {'User-Agent':user_agent}
         
        webData    = requests.get(url + 'o1',headers=headers).text
        soup       = BeautifulSoup(webData,'lxml')
         
         
        sum        = soup.find('span',class_="num").text.replace("套","")
        ave        = int(sum) / 32
        forNum     = int(ave)
 
        if forNum < ave:
            forNum = forNum + 1
 
 
        for x in range(forNum):
            webData    = requests.get(url + 'o' + str(x + 1),headers=headers).text
            soup       = BeautifulSoup(webData,'lxml')
            find_list  = soup.find('div',class_="f-main-list").find_all('div',class_="f-list-item ershoufang-list")
 
            for dl in find_list:
                 
                print(dl.find('a',class_="js-title value title-font").text,end='|') # 名称
 
                # 中间 5 个信息
                tempDD = dl.find('dd',class_="dd-item size").find_all('span')
                for tempSpan in tempDD:
                    if not tempSpan.text == '' :
                        print(tempSpan.text.replace("\n", ""),end='|')
 
                 
                print(dl.find('span',class_="area").text.replace(" ","").replace("\n",""),end='|') # 地址
                 
                print(dl.find('div',class_="price").text.replace(" ","").replace("\n",""),end='|') # 价钱
                 
                print(dl.find('div',class_="time").text.replace(" ","").replace("\n",""),end="|") # 平均
                 
                print("http://chaozhou.ganji.com" + dl['href'],end="|") # 地址
 
                print(str(x + 1))
 
if __name__ == '__main__':
    temp = GanJi()
    temp.get("http://chaozhou.ganji.com/fang5/xiangqiao/")

  

最新文章

  1. JSTREE 实现AJAX重载入时刷新所有节点树
  2. [LeetCode] Simplify Path 简化路径
  3. Node.js学习笔记
  4. CLR via C#(05)- 访问限定、数据成员
  5. 第1章 Java中常用字符串方法总结
  6. @propetry参数
  7. linux ssh免密码登录设置
  8. CentOS7 MongoDB安裝
  9. Facebook
  10. 21个很棒的jQuery分页插件下载
  11. 如何让EcStore和微博同步来推广网站
  12. socketio 握手前中断报错
  13. 学习笔记_J2EE_SpringMVC_01_入门
  14. 奇异值分解(SVD)与在降维中的应用
  15. Rocket Typist for Mac(增强型文本快速输入工具)破解版安装
  16. 交互软件Axure—高保真原型
  17. oracle imp 报12154错误解决办法
  18. Leetcode 之Flatten Binary Tree to Linked List(50)
  19. VM虚拟机不能上网的问题解决
  20. swiper不能手指滑动翻页的解决办法

热门文章

  1. springboot整合log4j2遇到的一个坑
  2. jquery向上滚动页面的写法
  3. JVM的内存分配垃圾回收策略
  4. 使用无图形界面启动Centos
  5. Python中的条件判断、循环以及循环的终止
  6. T100-----调试程序,快速定位到错误行
  7. AS3.0 字母大小写转换
  8. 集成maven和Spring boot的profile
  9. tkinter学习笔记_03
  10. HTML5单页框架View.js介绍