吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 8799|回复: 45
收起左侧

[Python 转载] 【Python】赶集网二手房爬虫 (可扩展)

  [复制链接]
ccph 发表于 2018-8-3 17:14
最近接了个义务单,是关于赶集网的二手房爬虫。


github:https://github.com/CcphAmy/pythonDemo

赶集网.png

[Python] 纯文本查看 复制代码
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/")

免费评分

参与人数 6吾爱币 +6 热心值 +5 收起 理由
ldick123 + 1 谢谢@Thanks!
吾爱妹子涛 + 1 + 1 我很赞同!
安河桥 + 1 + 1 我很赞同!
莫名堂 + 1 + 1 热心回复!
mengsiyiren + 1 + 1 热心回复!
s35485677 + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| ccph 发表于 2018-8-6 17:47
l12h1 发表于 2018-8-6 17:27
谢谢大大分享!
我觉得不同城市可以用汉字转拼音的方法 来构建url
然后列一个主要城市的列表 抓取不同城 ...

具体可以完善,而且类型还可以更改
l12h1 发表于 2018-8-6 17:27
谢谢大大分享!
我觉得不同城市可以用汉字转拼音的方法 来构建url
然后列一个主要城市的列表 抓取不同城市的数据
最后持久化一下就行
s35485677 发表于 2018-8-3 17:21
andyzgs 发表于 2018-8-3 17:22
非常不错,下载学习下。。。
s35485677 发表于 2018-8-3 17:24
俺想买房,能不能教教怎么用啊?
陌森 发表于 2018-8-3 17:27
感谢分享
waipojie123 发表于 2018-8-3 17:28
感谢分享
kk1212 发表于 2018-8-3 17:31
Python确实是非常的强大,比PHP强大多了
Jerry_bean 发表于 2018-8-3 17:39
要是支持手动输入城市,选择需要查询的页码总数,会更方便一些吧
mengsiyiren 发表于 2018-8-3 17:40
不会用系列
zs820553471 发表于 2018-8-3 20:32
还有没有这样的单,i want
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-25 21:57

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表