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

相关推荐
IT毕设实战小研2 天前
电影数据可视化推荐系统
大数据·后端·爬虫·python·算法·信息可视化·课程设计
笔触狂放2 天前
第3章 抓取静态网页数据
爬虫·python
笔触狂放2 天前
第1章 认识网络爬虫
爬虫
深蓝电商API2 天前
Referer 校验原理
爬虫·referer
天空1103 天前
你的网站在 AI 眼里是什么样:三类「人能看见、AI 看不见」的内容
爬虫·seo
zx_741484813 天前
【Python入门】爬虫实战:Requests + XPath 从基础到实战
开发语言·爬虫·python
for_ever_love__3 天前
python爬虫: GET请求与POST请求
开发语言·爬虫·python·网络编程
IT毕设实战小研3 天前
基于安卓的考研资讯系统设计与实现
android·大数据·vue.js·爬虫·python·考研·课程设计
IT毕设实战小研3 天前
基于安卓的空气质量查询系统
android·大数据·vue.js·爬虫·python·django·课程设计
benchmark_cc3 天前
1000只ETF的5分钟K线如何批量获取?QuantDash分页策略与高性能Python实践
开发语言·人工智能·爬虫·python·算法·quantdash·量化数据源