Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >吃饱了么! 数据抓取

吃饱了么! 数据抓取

作者头像
不止于python
发布于 2022-05-31 12:15:05
发布于 2022-05-31 12:15:05
43500
代码可运行
举报
文章被收录于专栏:不止于python不止于python
运行总次数:0
代码可运行

抓取思路

结果: 最终实现通过经纬度、商家、关键字等抓取数据

1. 使用charles进行抓包

2. Chrom调试

3. 找出商品请求api

4. 破解sign 和 其它请求参数

5. 使用代码请求单个api是否成功

6. 使用queue进行商店, 分类, 商品系统化抓取

7. 使用协程并发抓取

8. 数据清理, 存储到mongo

项目目录

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
.
├── conf
│   ├── AuthConfig.py
│   ├── __pycache__
│   │   └── AuthConfig.cpython-36.pyc
│   ├── city.py
│   ├── log.conf
│   ├── project.conf
│   └── untitled.py
├── log
│   └── eleme_test.log
├── spider
│   ├── REMEAD.md
│   ├── __pycache__
│   │   └── auto_crawl.cpython-36.pyc
│   ├── auto_crawl.py
│   ├── eleme.py
│   ├── foods.json
│   ├── jlf.xlsx
│   ├── new_eleme.py
│   └── shops.json
├── tools
│   ├── __pycache__
│   │   ├── cookie_manager.cpython-36.pyc
│   │   ├── logger.cpython-36.pyc
│   │   ├── proxy_manager.cpython-36.pyc
│   │   ├── tools.cpython-36.pyc
│   │   └── url_format.cpython-36.pyc
│   ├── cookie_manager.py
│   ├── logger.py
│   ├── proxy_manager.py
│   ├── sign.js
│   ├── tools.py
│   └── url_format.py
└── utils
    ├── __init__.py
    ├── __pycache__
    │   ├── __init__.cpython-36.pyc
    │   ├── download.cpython-36.pyc
    │   ├── mongo.cpython-36.pyc
    │   ├── redis_sql.cpython-36.pyc
    │   └── tools.cpython-36.pyc
    ├── download.py
    ├── foods.json
    ├── mongo.py
    ├── redis_sql.py
    ├── shop.json
    └── tools.py

9 directories, 38 files

商店详情代码

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
    def crawl_shop_info_handler(self, new_shop):
        """
        Crawl shop info, contain phone and categorys
        :param new_shop: shop info
        :type new_shop: dict
        :return: None
        :rtype: NoneType
        """
        city_info = new_shop["cityInfo"]

        # self.mongo_db.upsert("shops", new_shop)
        self.mark_job_status("shops", new_shop, 1)

        if "shopInfo" not in new_shop:
            shop_info = {
                "storeId": new_shop["storeId"],
                "wid": new_shop["wid"],
                "eleId": new_shop["_id"],
                "cityId": city_info["_id"]
            }
            res = self._get_request_data("shop", city_info, **shop_info)
            shop_data = res.get("data", {}).get("data", {})
            new_shop["shopInfo"] = shop_data.get("shopInfo", {})

        if "shopCategorys" not in new_shop:
            cate_data = {
                "storeId": new_shop["storeId"]
            }
            res = self._get_request_data("cates", city_info, **cate_data)
            cate_ids = {}
            cate_lists = res.get("data", {}).get("data", [])
            for cate in cate_lists:
                one_data = self.cate_id_join(cate)
                for two_level in cate.get("detail", []):
                    status = {"status": 0}
                    two_data = self.cate_id_join(two_level)
                    cate_info = self.cate_joint_symbol.join([one_data, two_data])
                    cate_ids[cate_info] = status

            new_shop["shopCategorys"] = cate_ids
        new_shop["update_time_stamp"] = int(time.time() * 1000)
        new_shop["status"] = 2
        self.mongo_db.upsert("shops", new_shop)

        self.logger.debug("Get shop:%s info success, cate total: %s" % (new_shop["_id"], len(cate_ids)))

商品信息

商店信息

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-12-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验