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

相关推荐
火龙谷11 小时前
【爬虫】12306查票
爬虫
ζ小菜鸡12 小时前
我用Deepseek + 亮数据爬虫神器 1小时做出輿情分析器
爬虫·bright data
q5673152314 小时前
Go语言多线程爬虫与代理IP反爬
开发语言·爬虫·tcp/ip·golang
Go Dgg21 小时前
Go语言实现豆瓣电影Top250爬虫
开发语言·爬虫·golang
攻城狮7号1 天前
Python爬虫第20节-使用 Selenium 爬取小米商城空调商品
开发语言·数据库·爬虫·python·selenium
奋斗者1号1 天前
浏览器自动化与网络爬虫实战:工具对比与选型指南
运维·爬虫·自动化
q567315232 天前
Node.js数据抓取技术实战示例
爬虫·python·scrapy·node.js
.生产的驴2 天前
SpringBoot 集成滑块验证码AJ-Captcha行为验证码 Redis分布式 接口限流 防爬虫
java·spring boot·redis·分布式·后端·爬虫·tomcat
来自星星的坤2 天前
Python 爬虫基础入门教程(超详细)
开发语言·爬虫·python
浩皓素2 天前
Python网络爬虫:从入门到实践
爬虫·python