python 字符串替换

字符串替换工具。。。。

import re
import urllib.parse
strs=""
#  这是抓的包
aa = "user_id=10655107&as_driver=0&cross_city=1&from_country=CN&from_province=%E5%8C%97%E4%BA%AC%E5%B8%82&from_city=%E5%8C%97%E4%BA%AC%E5%B8%82&from_county=%E4%B8%9C%E5%9F%8E%E5%8C%BA&from_street=%E7%8E%8B%E5%BA%9C%E4%BA%95%E5%A4%A7%E8%A1%97201%E5%8F%B7%E9%99%84%E8%BF%91&from_location=%E5%8C%97%E4%BA%AC%E5%88%A9%E7%94%9F%E4%BD%93%E8%82%B2%E5%95%86%E5%8E%A6%E9%99%84%E8%BF%91&from_latitude=39.91640441574212&from_longitude=116.41024300984193&from_administrative_city=%E5%8C%97%E4%BA%AC%E5%B8%82&to_country=CN&to_province=%E6%B2%B3%E5%8C%97%E7%9C%81&to_city=%E9%AB%98%E7%A2%91%E5%BA%97%E5%B8%82&to_county=%E9%AB%98%E7%A2%91%E5%BA%97%E5%B8%82&to_street=%E9%AB%98%E7%A2%91%E5%BA%97%E5%B8%82%E9%99%84%E8%BF%91&to_location=%E6%A1%A5%E5%8F%A4%E5%AF%BA%E6%9D%91%E9%99%84%E8%BF%91&to_latitude=39.156288425025814&to_longitude=116.08927379135675&to_administrative_city=%E9%AB%98%E7%A2%91%E5%BA%97%E5%B8%82&mileage=116.0&departure_datetime=2020-06-24%2017%3A33%3A14&acceptable_departure_datetime=2020-06-24%2018%3A33%3A14&departure_quarters=0&number_of_passengers=1&message=&recommended_price=0.0&accept_recommended_price=0&bonus=0.0&due=9400.0&old_money=9400.0&public=0&os=Android5.17.0&status=1&is_public=0"
y=urllib.parse.unquote(aa) #转编码

#抓包程序改成 需要加密的
s="accept_recommended_price=0&acceptable_departure_datetime=2020-06-22 21:45:01&as_driver=0&bonus=0.0&cross_city=1&departure_datetime=2020-06-22 21:45:01&departure_quarters=0&due=23100.0&from_administrative_city=北京市&from_city=北京市&from_country=CN&from_county=东城区&from_latitude=39.940147&from_location=新华文化大厦&from_longitude=116.408121&from_province=河北省&from_street=交道口南大街15号&is_public=0&message=&mileage=401.0&number_of_passengers=1&old_money=23100.0&os=Android5.17.0&public=0&recommended_price=0.0&status=1&to_administrative_city=邢台市&to_city=邢台市&to_country=CN&to_county=桥东区&to_latitude=37.08913&to_location=邢台学院&to_longitude=114.505085&to_province=河北省&to_street=泉北东大街88号&user_id=10655107SInsak45DIj"
a = s.split("&")

for i in a:
    if i in y:
        strs+=i+"&"
    else:
        listi=i.split("=")
        ref = re.findall(str(listi[0])+'=(.*?)&',y)
        restr=listi[0]+"="+ref[0]+"&"
        strs+=listi[0]+restr
print(strs[0:-1]+"SInsak45DIj")# 这是替换排序之后的

你可能感兴趣的:(Python)