当前位置: 首页 > wzjs >正文

多语言网站个人婚礼网站模板

多语言网站,个人婚礼网站模板,wordpress文章保存图片,成都今天消息1、准备需要爬取的小区名称,存放在txt文本中 # 从文件中读取小区名称 def read_residential_names(file_path):"""从文件中读取小区名称:param file_path: 文件路径:return: 小区名称列表"""if not os.path.exists(file_path):print…

1、准备需要爬取的小区名称,存放在txt文本中

# 从文件中读取小区名称
def read_residential_names(file_path):"""从文件中读取小区名称:param file_path: 文件路径:return: 小区名称列表"""if not os.path.exists(file_path):print(f"File not found: {file_path}")return []with open(file_path, "r", encoding="utf-8") as file:names = [line.strip() for line in file.readlines() if line.strip()]return names

2、需要根据住宅区名称和所在地区获取其UID

def get_residential_uid(residential_name, region, bmap_key):"""根据住宅区名称和所在地区获取其UID:param residential_name: 住宅区名称:param region: 地区:param bmap_key: 百度地图API密钥:return: UID或None"""bmap_localsearch_url = f"http://api.map.baidu.com/place/v2/search?query={residential_name}&region={region}&output=json&city_limit=true&ak={bmap_key}"s = requests.Session()s.mount('http://', HTTPAdapter(max_retries=3))s.mount('https://', HTTPAdapter(max_retries=3))try:response = s.get(bmap_localsearch_url, timeout=5, headers={"Connection": "close"})data = response.json()if data['status'] == 0 and len(data['results']) > 0:for info in data['results']:if '-' not in info['name']:return info['uid']print(f"No valid UID found for {residential_name} in {region}")return Noneelse:print(f"No results found for {residential_name} in {region}")return Noneexcept Exception as e:print(f"Error in get_residential_uid: {e}\nURL: {bmap_localsearch_url}")return None

3、根据UID获取住宅区的边界信息

def get_boundary_by_uid(uid, bmap_key):"""根据UID获取住宅区的边界信息:param uid: 百度地图目标UID:param bmap_key: 百度地图API密钥:return: 边界坐标字符串或None"""bmap_boundary_url = f"http://map.baidu.com/?reqflag=pcmap&from=webmap&qt=ext&uid={uid}&ext_ver=new&l=18&ak={bmap_key}"s = requests.Session()s.mount('http://', HTTPAdapter(max_retries=3))s.mount('https://', HTTPAdapter(max_retries=3))try:response = s.get(bmap_boundary_url, timeout=5, headers={"Connection": "close"})data = response.json()if 'content' in data and 'geo' in data['content']:geo = data['content']['geo']coordinates = []for point in geo.split('|')[2].split('-')[1].split(','):coordinates.append(point.strip(';'))boundary = ';'.join([f"{coordinates[i]},{coordinates[i + 1]}" for i in range(0, len(coordinates), 2)])return boundaryelse:print(f"No boundary information found for UID: {uid}")return Noneexcept Exception as e:print(f"Error in get_boundary_by_uid: {e}\nURL: {bmap_boundary_url}")return None

4、解析百度地图返回的geo数据,提取坐标点

def parse_geo_data(geo_data):"""解析百度地图返回的geo数据,提取坐标点:param geo_data: 百度地图返回的geo字符串:return: 包含(x, y)坐标对的列表"""if not geo_data or '|' not in geo_data:return []try:# 提取详细坐标部分coordinates = geo_data.split('|')[2].split('-')[1].split(',')# 将坐标转换为(x, y)对return [(float(coordinates[i].strip(';')), float(coordinates[i+1].strip(';'))) for i in range(0, len(coordinates)-1, 2)]except Exception as e:print(f"Error parsing geo data: {e}")return []

5、将Web Mercator坐标转换为WGS-84经纬度坐标

def web_mercator_to_wgs84(x, y):"""将Web Mercator坐标转换为WGS-84经纬度坐标:param x: Web Mercator X坐标:param y: Web Mercator Y坐标:return: WGS-84经纬度坐标 (lon, lat)"""transformer = Transformer.from_crs("EPSG:3857", "EPSG:4326")return transformer.transform(x, y)

6、将数据保存到CSV文件中

def save_to_csv(data, filename="output.csv"):"""将数据保存到CSV文件中:param data: 包含坐标的字典:param filename: 输出文件名"""# 获取文件的目录部分directory = os.path.dirname(filename)# 如果目录不为空,则创建目录if directory:os.makedirs(directory, exist_ok=True)# 写入CSV文件with open(filename, mode="w", newline="", encoding="utf-8") as file:writer = csv.writer(file)writer.writerow(["Residential Name", "Longitude", "Latitude"])  # 写入表头for name, coords in data.items():for coord in coords.split(';'):lon, lat = coord.split(',')writer.writerow([name, lon, lat])  # 写入每一行数据print(f"Data saved to {filename}")

7、主函数,bmap_key输入百度地图API密钥,region 输入默认查询地区, input_file 输入小区名称存储文件。

if __name__ == "__main__":bmap_key = "***"  # 替换为你的百度地图API密钥region = "北京"  # 默认查询地区input_file = "**.txt"  # 小区名称文件output_file = "transformed_coordinates.csv"  # 输出文件# 读取小区名称residential_names = read_residential_names(input_file)if not residential_names:print("No residential names found in the input file.")exit()# 存储所有小区的边界坐标all_boundaries = {}for residential_name in residential_names:print(f"Processing: {residential_name}")uid = get_residential_uid(residential_name, region, bmap_key)if uid:boundary = get_boundary_by_uid(uid, bmap_key)if boundary:all_boundaries[residential_name] = boundaryelse:print(f"Failed to get boundary information for {residential_name}.")else:print(f"Failed to get UID for {residential_name}.")# 将结果保存到CSV文件save_to_csv(all_boundaries, filename=output_file)

完整代码下载
https://download.csdn.net/download/cc605523/90592963


文章转载自:

http://aIyDq1TY.Lpppg.cn
http://Ov5m9F9A.Lpppg.cn
http://YnYOAGvR.Lpppg.cn
http://xuNa34qV.Lpppg.cn
http://QCdrGlfI.Lpppg.cn
http://cjcJptHe.Lpppg.cn
http://eC1qAVHL.Lpppg.cn
http://fstdjUYh.Lpppg.cn
http://Zeg78lZG.Lpppg.cn
http://qwqO0u8K.Lpppg.cn
http://4A0YJZU3.Lpppg.cn
http://WbXum6jp.Lpppg.cn
http://m8pTANIQ.Lpppg.cn
http://HqpJr4U7.Lpppg.cn
http://HopbI3DJ.Lpppg.cn
http://ldgKsVqr.Lpppg.cn
http://uAFEASrN.Lpppg.cn
http://ODLmK2Nw.Lpppg.cn
http://6gEAP2yT.Lpppg.cn
http://vxkRKhk2.Lpppg.cn
http://r3oGa6zV.Lpppg.cn
http://3opNnhwY.Lpppg.cn
http://GJfkc8sy.Lpppg.cn
http://APIzm9uK.Lpppg.cn
http://CVvKfsZ5.Lpppg.cn
http://oa6gn92G.Lpppg.cn
http://pjRV7YRS.Lpppg.cn
http://i7kS6DzC.Lpppg.cn
http://vIt5LVPP.Lpppg.cn
http://pyo04wJl.Lpppg.cn
http://www.dtcms.com/wzjs/743300.html

相关文章:

  • 黑龙江省住房与城乡建设厅网站汽车配件外贸网站
  • 深圳网站设计服务公网站的优化哪个好
  • 网站建设助手没有网站 可以做百度口碑吗
  • 谷歌建站多少钱广东哪里有网站建设
  • 用dw做网站的空格怎么打个体做敦煌网站怎么样
  • 二级域名建站app在线设计
  • 天津工程建设协会网站直播网站app开发
  • 江西建设厅培训网站wap 2.0的网站
  • 烟台做网站系统中国十大培训机构影视后期
  • 丽水手机网站建设小网站开发用哪些技术
  • 墨刀做网站上下滑动的交互濮阳网站建设在哪里
  • 中国网站排名网网站建设的费用结构
  • 网站设计前景怎样邢台市官网
  • wordpress设计类网站怎么创建自己公司的网站
  • 民宿网站开发方案垂直网站建设的关键因素
  • 网站建设 备案什么意思备案关闭网站
  • 徐州网站建设优化宣传网站运营的含义是什么
  • 织梦技术个人网站模板sae wordpress 主题
  • gps建站教程视频安卓wordpress
  • wordpress零基础建站教程最专业的网站建设收费
  • 视频直播免费网站建设网页论坛
  • 网站开发项目质量控制措施零基础怎么学网页设计
  • 苏州企业网站设计开发wordpress防止ddos插件
  • 做公司网站的专业公司深圳wordpress E405
  • 人才招聘网站开发 源代码自己创业做原公司一样的网站
  • 旅游网站前端模板建设工程有限公司网站
  • 河北提供网站制作公司哪家专业什么软件可以推广自己的产品
  • 建设工程案例网站go cms wordpress
  • 高清素材图片的网站电子商城网站开发
  • 园区门户网站建设wordpress网站模板下载