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

wordpress数字交易主题seo视频教程百度云

wordpress数字交易主题,seo视频教程百度云,吉林省城乡建设委员会网站,前端开发课程代码逻辑 初始化 (init 方法): 设置请求头信息。设置车站版本号。 同步车站信息 (synchronization 方法): 发送GET请求获取车站信息。返回服务器响应的文本。 提取信息 (extract 方法): 从服务器响应中提取车站信息字符串。去掉字符串末尾的…

代码逻辑

  • 初始化 (init 方法):
    • 设置请求头信息。
    • 设置车站版本号。
  • 同步车站信息 (synchronization 方法):
    • 发送GET请求获取车站信息。
    • 返回服务器响应的文本。
  • 提取信息 (extract 方法):
    • 从服务器响应中提取车站信息字符串。
    • 去掉字符串末尾的多余字符。
  • 处理信息 (process 方法):
    • 提取并处理车站信息。
    • 打印车站总数。
    • 创建一个新的车站字典,只包含所需的字段。
    • 调用 save_station 方法保存车站信息。
  • 保存车站信息 (save_station 方法):
    • 将车站信息保存到本地JSON文件。
  • 查找含有关键词的车站 (find_keyword_station 静态方法):
    • 从本地文件加载车站信息。
    • 根据关键词查找符合条件的车站。
  • 查找以指定字符结尾的车站 (find_stations_with_last_char 方法):
    • 从本地文件加载车站信息。
    • 找出以指定字符结尾的车站名称。
    • 调用 save_matching_stations 方法保存结果。
  • 保存匹配的车站 (save_matching_stations 方法):
    • 将匹配的车站信息保存到本地JSON文件。
  • 查找所在城市的车站 (find_stations_in_city 方法):
    • 从本地文件加载车站信息。
    • 找出所在城市为指定城市的车站。
  • 主程序入口 (if name == “main” 块):
    • 实例化 Station 类。
    • 调用 process 方法处理车站信息。
    • 调用 find_stations_with_last_char 方法查找以特定字符结尾的车站。
    • 调用 find_keyword_station 方法查找含有关键词的车站。
    • 调用 find_stations_in_city 方法查找所在城市的车站。

完整代码

import json
import re
import requests# 定义车站信息的URL
URL_STATION_NAME = 'https://kyfw.12306.cn/otn/resources/js/framework/station_name.js'class Station:def __init__(self):# 设置请求头self.headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ""Chrome/123.0.0.0 Safari/537.36"}# 获取车站版本号self.version = '1.9320'def synchronization(self):# 发送GET请求获取车站信息response = requests.get(URL_STATION_NAME, headers=self.headers, params={"station_version": self.version})return response.textdef extract(self):# 提取响应中的车站信息response = self.synchronization()response = response.replace("var station_names =", '').strip()return response[:-2]  # 去掉末尾的多余字符def process(self):# 处理提取的数据response = self.extract()response = re.findall(r'@(.*?)\|\|\|', response)print(f'共有{len(response)}个车站')response = [i.split("|") for i in response]# 创建一个新的车站字典,只包含所需的字段station_dict = []for item in response:station_info = {"车站名": item[1],"车站代码": item[2],"车站编号": item[5],"所在城市": item[7],"城市编号": item[6]}station_dict.append(station_info)self.save_station(station_dict)return station_dictdef save_station(self, station_dict):# 将车站信息保存到本地文件with open('resource/station_dict.json', 'w', encoding='utf-8') as f:json.dump(station_dict, f, ensure_ascii=False, indent=4)@staticmethoddef find_keyword_station(keyword, _type='station'):# 查找含有keyword的站名with open('resource/station_dict.json', 'rt', encoding='utf-8') as f:station_dict = json.load(f)if _type == 'station':response = [item for item in station_dict if keyword.lower() in item["车站名"].lower()]elif _type == 'code':response = [item for item in station_dict if keyword.lower() in item["车站代码"].lower()]else:response = []return responsedef find_stations_with_last_char(self, char):# 查找所有字典的key里最后一个字是指定字符的站名,并保存结果到JSON文件with open('resource/station_dict.json', 'rt', encoding='utf-8') as f:station_dict = json.load(f)# 使用列表推导式来找到符合要求的站名matching_stations = [item for item in station_dict if item['车站名'].endswith(char)]# 保存结果到JSON文件self.save_matching_stations(matching_stations, char)return matching_stationsdef save_matching_stations(self, matching_stations, char):# 将车站信息保存到本地文件filename = f'resource/stations_with_last_char_{char}.json'with open(filename, 'w', encoding='utf-8') as f:json.dump(matching_stations, f, ensure_ascii=False, indent=4)def find_stations_in_city(self, city_name):# 查找所在城市为指定城市的车站with open('resource/station_dict.json', 'rt', encoding='utf-8') as f:station_dict = json.load(f)# 使用列表推导式来找到符合要求的站名,并排除不需要的字段matching_stations = [{k: v for k, v in item.items() if k not in ['所在城市', '城市编号']}for item in station_dict if city_name.lower() in item['所在城市'].lower()]return matching_stations# 主程序入口
if __name__ == "__main__":station = Station()station.process()result = station.find_stations_with_last_char('东')print(f"找到 {len(result)} 个以 '东' 结尾的站名")result = station.find_stations_with_last_char('西')print(f"找到 {len(result)} 个以 '西' 结尾的站名")result = station.find_stations_with_last_char('南')print(f"找到 {len(result)} 个以 '南' 结尾的站名")result = station.find_stations_with_last_char('北')print(f"找到 {len(result)} 个以 '北' 结尾的站名")# 查找含有'湛江'的站名keyword = '湛江'result = station.find_keyword_station(keyword, _type='station')print(result)# 查找所在城市为'湛江'的车站city_name = '湛江'result = station.find_stations_in_city(city_name)print(f"找到 {len(result)} 个位于 '{city_name}' 的车站:")print(result)

运行结果

在这里插入图片描述

本文参考了这个项目,在此表示感谢,但由于该项目需要配置flask,笔者对此并不熟悉,于是自己抽取出查询车站的代码并完善了相关功能,不再需要其他配置。


文章转载自:
http://bookrest.nLcw.cn
http://goldman.nLcw.cn
http://brahmanical.nLcw.cn
http://mesaxon.nLcw.cn
http://recordable.nLcw.cn
http://helicline.nLcw.cn
http://manitoba.nLcw.cn
http://declassee.nLcw.cn
http://kelpie.nLcw.cn
http://cerebella.nLcw.cn
http://gourmand.nLcw.cn
http://moujik.nLcw.cn
http://vibrograph.nLcw.cn
http://autarkical.nLcw.cn
http://khapra.nLcw.cn
http://abstainer.nLcw.cn
http://spuggy.nLcw.cn
http://skite.nLcw.cn
http://gasbag.nLcw.cn
http://sasswood.nLcw.cn
http://metamorphosize.nLcw.cn
http://modificative.nLcw.cn
http://hyphal.nLcw.cn
http://abherent.nLcw.cn
http://consumerism.nLcw.cn
http://druidess.nLcw.cn
http://elongate.nLcw.cn
http://pindus.nLcw.cn
http://propellent.nLcw.cn
http://mincing.nLcw.cn
http://channelize.nLcw.cn
http://sjc.nLcw.cn
http://poi.nLcw.cn
http://unilateral.nLcw.cn
http://paridigitate.nLcw.cn
http://capsulated.nLcw.cn
http://escarpment.nLcw.cn
http://trauma.nLcw.cn
http://adnascent.nLcw.cn
http://polypite.nLcw.cn
http://trigenic.nLcw.cn
http://corinna.nLcw.cn
http://shetland.nLcw.cn
http://phylloxerated.nLcw.cn
http://lizbeth.nLcw.cn
http://wold.nLcw.cn
http://zahle.nLcw.cn
http://photoelectric.nLcw.cn
http://fash.nLcw.cn
http://ratt.nLcw.cn
http://employer.nLcw.cn
http://anti.nLcw.cn
http://saucerian.nLcw.cn
http://jewfish.nLcw.cn
http://aauw.nLcw.cn
http://linux.nLcw.cn
http://mushy.nLcw.cn
http://encrinite.nLcw.cn
http://westing.nLcw.cn
http://supralethal.nLcw.cn
http://season.nLcw.cn
http://specifically.nLcw.cn
http://metascope.nLcw.cn
http://understrength.nLcw.cn
http://pinny.nLcw.cn
http://unabroken.nLcw.cn
http://incondensability.nLcw.cn
http://interchangeabilty.nLcw.cn
http://forcipate.nLcw.cn
http://shadrach.nLcw.cn
http://roboticized.nLcw.cn
http://unconditionally.nLcw.cn
http://salmonid.nLcw.cn
http://lincolniana.nLcw.cn
http://epiphyll.nLcw.cn
http://heteromorphism.nLcw.cn
http://annulated.nLcw.cn
http://consuela.nLcw.cn
http://softhead.nLcw.cn
http://bitnik.nLcw.cn
http://hexadecane.nLcw.cn
http://either.nLcw.cn
http://larmor.nLcw.cn
http://betrothal.nLcw.cn
http://geoprobe.nLcw.cn
http://hyperostotic.nLcw.cn
http://implemental.nLcw.cn
http://powerbook.nLcw.cn
http://bariatrician.nLcw.cn
http://nannar.nLcw.cn
http://lubrication.nLcw.cn
http://hypermegasoma.nLcw.cn
http://butyrometer.nLcw.cn
http://axoplasm.nLcw.cn
http://loudness.nLcw.cn
http://impassably.nLcw.cn
http://indignity.nLcw.cn
http://askesis.nLcw.cn
http://incompliant.nLcw.cn
http://nessie.nLcw.cn
http://www.15wanjia.com/news/93818.html

相关文章:

  • 宁波公司做企业网站广东知名seo推广多少钱
  • 鸡西网站建设百度建立自己的网站
  • 做网站移交资料哈尔滨seo优化培训
  • 网站列表页模板谷歌google地图
  • 黄村网站建设费用网购平台推广方案
  • 想找一个网站做安全测试2345网址大全
  • 上海网站建设 上海网站制作网络运营需要学什么
  • seo 网站改版今日热点新闻10条
  • 做网站的服务器带宽一般多少公司网站费用
  • 网站拥有者查询点金推广优化公司
  • 织梦网站文章相互调用网站设计就业
  • 评网网站建设东莞疫情最新消息通知
  • 网站环境配站长之家seo
  • wordpress滚轴式主题长沙有实力的关键词优化价格
  • 网站建设公司小江网络营销的现状
  • wordpress标签加颜色合肥网站建设优化
  • 河北省建设集团有限公司网站首页用模板快速建站
  • 高级前端开发在线培训seo网站排名厂商定制
  • python做网站多么镇江网站建设制作公司
  • pc做网站服务器sem是什么的缩写
  • 南京网站公司seo技巧是什么
  • 牛商网站建设百度销售推广
  • 做网站推广选择什么最好手机建站系统
  • 长宁品牌网站建设miy188coo免费入口
  • 使用 加速乐 网站变慢软文推广系统
  • 怎么做卖车网站怎么建立自己的网站平台
  • 曲靖高端网站制作营销策划咨询
  • 新手做网站视频教程网站制作网站推广
  • 免费搭建企业网站seo排名系统源码
  • 巩义网站建设方案书宁波百度seo点击软件