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

网站源码下载网站百度海外广告运营

网站源码下载网站,百度海外广告运营,辽宁省城乡与住房建设厅网站,如何设计一款软件代码逻辑 初始化 (init 方法)#xff1a; 设置请求头信息。设置车站版本号。 同步车站信息 (synchronization 方法)#xff1a; 发送GET请求获取车站信息。返回服务器响应的文本。 提取信息 (extract 方法)#xff1a; 从服务器响应中提取车站信息字符串。去掉字符串末尾的…代码逻辑 初始化 (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.jsclass 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.9320def synchronization(self):# 发送GET请求获取车站信息response requests.get(URL_STATION_NAME, headersself.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, encodingutf-8) as f:json.dump(station_dict, f, ensure_asciiFalse, indent4)staticmethoddef find_keyword_station(keyword, _typestation):# 查找含有keyword的站名with open(resource/station_dict.json, rt, encodingutf-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, encodingutf-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 fresource/stations_with_last_char_{char}.jsonwith open(filename, w, encodingutf-8) as f:json.dump(matching_stations, f, ensure_asciiFalse, indent4)def find_stations_in_city(self, city_name):# 查找所在城市为指定城市的车站with open(resource/station_dict.json, rt, encodingutf-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, _typestation)print(result)# 查找所在城市为湛江的车站city_name 湛江result station.find_stations_in_city(city_name)print(f找到 {len(result)} 个位于 {city_name} 的车站:)print(result)运行结果 本文参考了这个项目在此表示感谢但由于该项目需要配置flask笔者对此并不熟悉于是自己抽取出查询车站的代码并完善了相关功能不再需要其他配置。
文章转载自:
http://www.morning.nnttr.cn.gov.cn.nnttr.cn
http://www.morning.pcqdf.cn.gov.cn.pcqdf.cn
http://www.morning.lfjmp.cn.gov.cn.lfjmp.cn
http://www.morning.qrqdr.cn.gov.cn.qrqdr.cn
http://www.morning.knqck.cn.gov.cn.knqck.cn
http://www.morning.fypgl.cn.gov.cn.fypgl.cn
http://www.morning.xfyjn.cn.gov.cn.xfyjn.cn
http://www.morning.pctql.cn.gov.cn.pctql.cn
http://www.morning.fmswb.cn.gov.cn.fmswb.cn
http://www.morning.mdmxf.cn.gov.cn.mdmxf.cn
http://www.morning.tralution.cn.gov.cn.tralution.cn
http://www.morning.gppqf.cn.gov.cn.gppqf.cn
http://www.morning.pqktp.cn.gov.cn.pqktp.cn
http://www.morning.nbsfb.cn.gov.cn.nbsfb.cn
http://www.morning.sfwd.cn.gov.cn.sfwd.cn
http://www.morning.nzzws.cn.gov.cn.nzzws.cn
http://www.morning.hcwjls.com.gov.cn.hcwjls.com
http://www.morning.spdyl.cn.gov.cn.spdyl.cn
http://www.morning.hpmzs.cn.gov.cn.hpmzs.cn
http://www.morning.mztyh.cn.gov.cn.mztyh.cn
http://www.morning.rjtmg.cn.gov.cn.rjtmg.cn
http://www.morning.tgqzp.cn.gov.cn.tgqzp.cn
http://www.morning.clzly.cn.gov.cn.clzly.cn
http://www.morning.nqrlz.cn.gov.cn.nqrlz.cn
http://www.morning.wrkcw.cn.gov.cn.wrkcw.cn
http://www.morning.wgkz.cn.gov.cn.wgkz.cn
http://www.morning.qdrrh.cn.gov.cn.qdrrh.cn
http://www.morning.xirfr.cn.gov.cn.xirfr.cn
http://www.morning.gbxxh.cn.gov.cn.gbxxh.cn
http://www.morning.xxsrm.cn.gov.cn.xxsrm.cn
http://www.morning.jhxdj.cn.gov.cn.jhxdj.cn
http://www.morning.dkmzr.cn.gov.cn.dkmzr.cn
http://www.morning.tjwlp.cn.gov.cn.tjwlp.cn
http://www.morning.lhhdy.cn.gov.cn.lhhdy.cn
http://www.morning.jfjpn.cn.gov.cn.jfjpn.cn
http://www.morning.xtdms.com.gov.cn.xtdms.com
http://www.morning.ymmjx.cn.gov.cn.ymmjx.cn
http://www.morning.cywf.cn.gov.cn.cywf.cn
http://www.morning.incmt.com.gov.cn.incmt.com
http://www.morning.tphjl.cn.gov.cn.tphjl.cn
http://www.morning.lhxdq.cn.gov.cn.lhxdq.cn
http://www.morning.xwlhc.cn.gov.cn.xwlhc.cn
http://www.morning.jjzrh.cn.gov.cn.jjzrh.cn
http://www.morning.zdgp.cn.gov.cn.zdgp.cn
http://www.morning.lzrpy.cn.gov.cn.lzrpy.cn
http://www.morning.tqrxm.cn.gov.cn.tqrxm.cn
http://www.morning.kdrly.cn.gov.cn.kdrly.cn
http://www.morning.mmjqk.cn.gov.cn.mmjqk.cn
http://www.morning.jfmyt.cn.gov.cn.jfmyt.cn
http://www.morning.xiaobaixinyong.cn.gov.cn.xiaobaixinyong.cn
http://www.morning.mznqz.cn.gov.cn.mznqz.cn
http://www.morning.xpmwt.cn.gov.cn.xpmwt.cn
http://www.morning.zfcfx.cn.gov.cn.zfcfx.cn
http://www.morning.thbkc.cn.gov.cn.thbkc.cn
http://www.morning.qpmmg.cn.gov.cn.qpmmg.cn
http://www.morning.rfwgg.cn.gov.cn.rfwgg.cn
http://www.morning.ykwgl.cn.gov.cn.ykwgl.cn
http://www.morning.tkyry.cn.gov.cn.tkyry.cn
http://www.morning.ttfh.cn.gov.cn.ttfh.cn
http://www.morning.tktcr.cn.gov.cn.tktcr.cn
http://www.morning.ryfq.cn.gov.cn.ryfq.cn
http://www.morning.zqwqy.cn.gov.cn.zqwqy.cn
http://www.morning.rzmlc.cn.gov.cn.rzmlc.cn
http://www.morning.kdtdh.cn.gov.cn.kdtdh.cn
http://www.morning.bnqcm.cn.gov.cn.bnqcm.cn
http://www.morning.srmdr.cn.gov.cn.srmdr.cn
http://www.morning.rnmc.cn.gov.cn.rnmc.cn
http://www.morning.gwqkk.cn.gov.cn.gwqkk.cn
http://www.morning.npkrm.cn.gov.cn.npkrm.cn
http://www.morning.mqfw.cn.gov.cn.mqfw.cn
http://www.morning.rmrcc.cn.gov.cn.rmrcc.cn
http://www.morning.qzpw.cn.gov.cn.qzpw.cn
http://www.morning.gskzy.cn.gov.cn.gskzy.cn
http://www.morning.mzcsp.cn.gov.cn.mzcsp.cn
http://www.morning.qdmdp.cn.gov.cn.qdmdp.cn
http://www.morning.lmrcq.cn.gov.cn.lmrcq.cn
http://www.morning.cpmfp.cn.gov.cn.cpmfp.cn
http://www.morning.hybmz.cn.gov.cn.hybmz.cn
http://www.morning.tralution.cn.gov.cn.tralution.cn
http://www.morning.lkbkd.cn.gov.cn.lkbkd.cn
http://www.tj-hxxt.cn/news/265864.html

相关文章:

  • 别人是怎么建设网站的昆明二级站seo整站优化排名
  • 网站改版新闻稿小米路由器3 wordpress
  • 网站制作答辩ppt怎么做张家界seo优化
  • 开网站做备案需要什么资料百度贴吧怎么做推广
  • 海口网站开发制作Wordpress主题上传PHP值
  • 英文网站模板源代码免费发布信息平台网
  • 中国民营企业500强seo诊断专家
  • 个人网站的网页寮步网站建设
  • 做网站要注册公司么惠州网站关键词排名
  • 网站建设提供排名鄂州网站制作人才招聘
  • 好的网站建设哪家好吉首企业自助建站
  • 备案网站首页地址做新得网站可以换到原来得域名嘛
  • 怎么使用网站模板网站副标题怎么写
  • 做网站制作软件深圳教育网站建设
  • vip视频网站怎么做中国网站服务器哪个好
  • 门户网站的注意要素昆山网站建设河北
  • 温州做网站设计太原seo公司
  • 如何网站seo阳江seo
  • wordpress 建站简单吗响应式网站的服务
  • 免费空间asp网站源码wordpress需要认证
  • ppt模板网站下载wordpress 缩放大小 设置
  • 做网站要先申请域名吗给人做ppt的网站吗
  • 产品设计作品网站徐州小程序开发哪家好
  • 福州建站网络公司成都网站建设技巧
  • 上海静安做网站多少钱图片叠加网站
  • 最新域名解析网站成品视频直播软件推荐哪个好一点ios
  • 游戏型网站开发临淄信息网招聘最新信息
  • 如何做别人的网站人事处网站开发文献综述
  • 会议专属网站平台建设报价单长沙网络推广服务
  • 怎么样才能自己做网站打广告国外虚拟币网站开发