# 替换请求中的搜索字段 defget_ref(file, cont): with open(file, encoding='utf-8') as f: lines = f.readlines() for line in lines: if'Referer'in line: start = line.find("&wd=") end = line.find("&rsv_pq=") old_str = line[start+4:end] new_str = parse.quote(cont) line = line.replace(old_str, new_str) return line
# 重新拼装需发送的报文 defget_req(file, cont): msg = '' with open(file, encoding='utf-8') as f: lines = f.readlines() for line in lines: if'GET'in line: line = 'GET ' + get_ref(file, cont)[9:-1] + ' HTTP/1.1' if'Referer'in line: line = get_ref(file, cont) if'Accept-Encoding'in line: continue line = line.strip('\n') + '\r\n' msg += line msg = bytes(msg, encoding="utf8") return msg
# 替换请求中的搜索字段 defget_ref(file, cont): with open(file, encoding='utf-16') as f: lines = f.readlines() for line in lines: if'Referer'in line: start = line.find("&wd=") end = line.find("&rsv_pq=") old_str = line[start+4:end] new_str = parse.quote(cont) line = line.replace(old_str, new_str) return line
# 重新拼装需发送的报文 defget_req(file, cont): msg = '' with open(file, encoding='utf-16') as f: lines = f.readlines() for line in lines: if'Request header:'in line: continue if'GET'in line: line = 'GET ' + get_ref(file, cont)[9:-1] + ' HTTP/1.1' if'Referer'in line: line = get_ref(file, cont) if'Accept-Encoding'in line: continue line = line.strip('\n') + '\r\n' msg += line msg = bytes(msg[:-4], encoding="utf8") return msg