代码有点问题,给你参考下:import urllib.request
import urllib.parse
import time as t
import json
import re
def timestamp():
str1 = t.time() * 1000
str1 = str(int(str1))
return str1
url = 'https://www74.woaifanyi.com/web_system/ilovetranslation_com/wwwroot/key/baidu/save/?ajaxtimestamp='
#url_2 = 'https://www74.woaifanyi.com/web_system/ilovetranslation_com/wwwroot/key/google/save/?ajaxtimestamp='
url = url + timestamp()
data = {
'fy_nr' : 'Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串、数字、元组等其他容器模型',
'y_s_y_y' : 'zh',
'm_b_y_y' : 'en'
}
#data_2 = {
# 'fy_nr' : 'Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串、数字、元组等其他容器模型',
# 'y_s_y_y' : 'zh-CN',
# 'm_b_y_y' : 'en'
# }
data = urllib.parse.urlencode(data).encode('utf-8')
response = urllib.request.urlopen(url, data)
html = response.read().decode('utf-8')
new_data = {'hhid' : html.split('"')[-2]}
new_data = urllib.parse.urlencode(new_data).encode('utf-8')
print('Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串、数字、元组等其他容器模型')
print('waiting...')
while True:
url = 'https://www74.woaifanyi.com/web_system/ilovetranslation_com/wwwroot/key/baidu/get/?ajaxtimestamp='
url = url + timestamp()
response = urllib.request.urlopen(url, new_data)
html = response.read().decode('utf-8')
if html[-3] == '2':
mod = '<p>([^"]+)<'
target = re.search(mod, html)
print(target.group(1))
break
t.sleep(0.1)
|