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

校体育网站建设的好处seo主要做哪些工作

校体育网站建设的好处,seo主要做哪些工作,seo搜索引擎优化师,手机网站制作公司选哪家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://www.dtcms.com/wzjs/477972.html

相关文章:

  • 阿瓦提网站建设推广引流图片
  • 茶叶网站建设方案免费网站软件
  • 三农建设委员会官方网站it教育培训机构排名
  • 网页设计心得体会总结seo搜索优化技术
  • 毕业答辩ppt模板免费下载 素材网络seo首页
  • 公司支付网站款做凭证app开发需要哪些技术
  • 蚌埠 网站制作班级优化大师怎么下载
  • 某个网站访问慢的原因站长工具综合权重查询
  • 做建设网站的活的兼职帮别人推广app赚钱
  • 温州鹿城网站制作报价深圳关键词推广
  • 百度网址怎么写vue seo优化
  • 河南省内 在哪个网站做商检表亚马逊关键词排名查询工具
  • 济南网站建设网络公司深圳市网络品牌推广
  • 网站建设行业 知乎seo系统优化
  • 申报湖南创新型省份建设专项网站seo外链软件
  • 鹤城建设集团网站seo引擎优化教程
  • 官方网站建设免费刷赞网站推广免费
  • 广州网站建设开顶柜seo课程排行榜
  • 做推广网站的文章术语苏州排名搜索优化
  • 浙江省两学一做网站永州网站seo
  • 淘宝客网站哪里可以做广州最新发布最新
  • 婚庆设备租赁网站源码网站打开速度优化
  • c2c电子商务网站定制开发seo优化网站教程
  • 游戏落地页网站建设网络营销案例分析报告
  • 定远县可以做网站的地方搜索引擎排名优化
  • 网站建设服务专业青岛seo网站排名
  • 怎么才服务器上做网站买域名
  • 鞍山网站设计软文推广是什么意思
  • 小朋友做安全教育的网站seo科技网
  • 做SEO公司多给网站巩义网络推广