Google地图瓦片爬虫——进阶版

紧接上一篇------Google地图瓦片爬虫

clash节点自动切换

为了防止一个IP地址访问频率过快问题,自动切换clash的节点

python 复制代码
def change_node(is_stop):
    while True:
        _r = requests.get("http://127.0.0.1:11053/proxies", headers=clash_headers, verify=False)
        # 这里匹配Lv开头的节点
        proxy_list = [proxy for proxy in _r.json()["proxies"]["XXX"]["all"] if proxy.startswith("Lv")]

        proxy = random.choice(proxy_list)

        payload = json.dumps({"name": proxy})
		# XXX替换为自己的分组名称
        requests.put("http://127.0.0.1:11053/proxies/XXX", headers=clash_headers, data=payload, verify=False)

        time.sleep(5)
        if is_stop.value:
            print("Finished.")
            break

多进程爬虫

  • get_tile:用于爬取瓦片
  • write_to_db:用于写入数据库
  • change_node:用于切换clash节点
python 复制代码
def main():
    is_stop = multiprocessing.Value("I", 0)

    db_path, db_name, tile_list = init_db()
    total = len(tile_list)
    print(total)

    # 创建任务队列
    data_queue = Queue()

    process_list = []
    p_number = 10
    step = total // p_number + 1
    for i in range(p_number + 1):
        process_list.append(
            Process(target=get_tile, args=(data_queue, db_path, db_name, tile_list[i * step:(i + 1) * step],)))

    process_list.append(Process(target=write_to_db, args=(data_queue, db_path, total, is_stop)))

    process_list.append(Process(target=change_node, args=(is_stop,)))

    for p in process_list:
        p.start()

    for p in process_list:
        p.join()

完整程序

下载地址:https://download.csdn.net/download/this_is_id/90343579

相关推荐
VW_4049 小时前
csdn-2026-11-23-第一站踩坑
爬虫·python
tryCbest18 小时前
Python 爬虫从入门到实战(二):进阶篇——反爬对抗、并发与动态页面
开发语言·爬虫·python
乌鲁木齐德润恒圣信息科技有限公司2 天前
AI爬虫怎么读你的网站:结构化标记实操
人工智能·爬虫
乌鲁木齐德润恒圣信息科技有限公司2 天前
智推纪元 子站架构技术拆解
大数据·人工智能·爬虫
tryCbest3 天前
Python 爬虫从入门到实战(一):基础篇——从零写出第一个爬虫
开发语言·爬虫·python
wuyk5554 天前
Spider-第20讲-综合实战可上线爬虫
大数据·爬虫·python·elasticsearch
wuyk5555 天前
Spider-第16讲-线程池与竞态问题
大数据·爬虫·python·elasticsearch·搜索引擎
wuyk5557 天前
Spider-第14讲-表单提交与CSRF
前端·爬虫·python·elasticsearch·csrf
wuyk5559 天前
Spider-第11讲-工程化改造与可维护性
大数据·爬虫·elasticsearch·搜索引擎
wuyk5559 天前
Spider-第12讲-asyncio异步并发爬取
大数据·爬虫·elasticsearch·搜索引擎