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

相关推荐
深蓝电商API9 小时前
Scrapy+Rredis实现分布式爬虫入门与优化
分布式·爬虫·scrapy
sugar椰子皮1 天前
【web补环境篇-0】document.all
爬虫
interception1 天前
js逆向之京东原型链补环境h5st
javascript·爬虫·网络爬虫
半路_出家ren2 天前
17.python爬虫基础,基于正则表达式的爬虫,基于BeautifulSoup的爬虫
网络·爬虫·python·网络协议·正则表达式·网络爬虫·beautifulsoup
我想吃烤肉肉2 天前
Playwright中page.locator和Selenium中find_element区别
爬虫·python·测试工具·自动化
lbb 小魔仙2 天前
【Python】零基础学 Python 爬虫:从原理到反爬,构建企业级爬虫系统
开发语言·爬虫·python
努力变大白2 天前
借助AI零基础快速学会Python爬取网页信息-以天眼查爬虫为例
人工智能·爬虫·python
AC赳赳老秦3 天前
Unity游戏开发实战指南:核心逻辑与场景构建详解
开发语言·spring boot·爬虫·搜索引擎·全文检索·lucene·deepseek