def getStationNamesVersion():
'''
?? station_names.js ??????????
'''
logging.captureWarnings(True)
url = "https://kyfw.12306.cn/otn/"
station_name_version = "" # ????? 0 , ????????????????
response = requests.get(url, verify=False)
content = response.text.encode("UTF-8")
soup = bs4.BeautifulSoup(content, "html.parser")
scripts = soup.findAll("script")
srcs = [] # ?? HTML ???? script ??? src ??
for i in scripts:
try: # ???? try ????? script ????? src ????
src = i['src']
srcs.append(src)
except:
pass
for i in srcs: # ??????????? , ??????????????? , ?????????????
if "station_name" in i: # ???? station_names ??? src
station_name_version = i.split("station_version=")[1] # ?????
# print "??????????? :" , station_name_version # ????
return station_name_version
评论列表
文章目录