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

相关推荐
一晌小贪欢1 天前
Python爬虫第6课:Selenium自动化浏览器与动态内容抓取
爬虫·python·selenium·网络爬虫·python基础·python3·pathon爬虫
B站_计算机毕业设计之家2 天前
计算机毕业设计:Python农业数据可视化分析系统 气象数据 农业生产 粮食数据 播种数据 爬虫 Django框架 天气数据 降水量(源码+文档)✅
大数据·爬虫·python·机器学习·信息可视化·课程设计·农业
爬虫程序猿2 天前
把 1688 商品详情搬进 MySQL:PHP 爬虫全链路实战(2025 版)
爬虫·python·音视频
一晌小贪欢3 天前
Python爬虫第7课:多线程与异步爬虫技术
开发语言·爬虫·python·网络爬虫·python爬虫·python3
一百天成为python专家3 天前
python爬虫入门(小白五分钟从入门到精通)
开发语言·爬虫·python·opencv·yolo·计算机视觉·正则表达式
wanfeng_093 天前
python爬虫学习
爬虫·python·学习
濑户川3 天前
基于DDGS实现图片搜索,文本搜索,新闻搜索
人工智能·爬虫·python
Moniane3 天前
Web爬虫指南
爬虫·算法
深蓝电商API3 天前
快速上手 Scrapy:5 分钟创建一个可扩展的爬虫项目
爬虫·python·scrapy
直有两条腿3 天前
【爬虫】浏览器插件
爬虫