下载google浏览器对应的webdriver :
https://blog.csdn.net/weixin_41522164/article/details/82775735
下载 browsermob-proxy 插件:
https://github.com/lightbody/browsermob-proxy
具体实现代码
import time
import pandas as pd
from selenium import webdriver
from browsermobproxy import Server
from selenium.webdriver.chrome.options import Optionsserver = Server(r'E:\code\000-render-tools\python-spider-master\subwaymap\browsermob-proxy-2.1.4\bin\browsermob-proxy.bat')
server.start()
proxy = server.create_proxy()chrome_options = Options()
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--proxy-server={0}'.format(proxy.proxy))driver = webdriver.Chrome(chrome_options=chrome_options)
proxy.new_har("amap", options={'captureHeaders': True, 'captureContent': True})
driver.get('https://www.amap.com/')# cross_lst = ['广顺北大街与广顺桥交叉口']path= './frm_roaditem20200806'
with open(path + '.csv', 'r',encoding='gbk') as rf:
df = pd.read_csv(rf)
cross_lst = df['name'].astype(str)for cross_name in cross_lst:
print(cross_name)
search_key = driver.find_element_by_id('searchipt')
search_key.clear()
search_key.send_keys(cross_name)
driver.find_element_by_id("searchbtn").click()result = proxy.har
# print(result)
for entry in result['log']['entries']:
_url = entry['request']['url']
if "/service/regeo" in _url:
print(_url)
time.sleep(1)
# _response = entry['response']
# _content = _response['content']['text']
# 获取接口返回内容
# print(_content)time.sleep(5)
# driver.quit()# 退出浏览器
【Selenium 高德地图根据名称获取坐标】
推荐阅读
- 推荐系统论文进阶|CTR预估 论文精读(十一)--Deep Interest Evolution Network(DIEN)
- Python专栏|数据分析的常规流程
- Python|Win10下 Python开发环境搭建(PyCharm + Anaconda) && 环境变量配置 && 常用工具安装配置
- Python绘制小红花
- Pytorch学习|sklearn-SVM 模型保存、交叉验证与网格搜索
- OpenCV|OpenCV-Python实战(18)——深度学习简介与入门示例
- python|8. 文件系统——文件的删除、移动、复制过程以及链接文件
- 爬虫|若想拿下爬虫大单,怎能不会逆向爬虫,价值过万的逆向爬虫教程限时分享
- 分布式|《Python3网络爬虫开发实战(第二版)》内容介绍
- java|微软认真聆听了开源 .NET 开发社区的炮轰( 通过CLI 支持 Hot Reload 功能)