新手求助 爬虫 求思路
求教 爬取 www74.woaifanyi.com 的翻译结果 求助诸位大神 不想给代码哪怕给个思路也行 我看了一下接口地址https://www74.woaifanyi.com/web_system/ilovetranslation_com/wwwroot/key/google/save/?ajaxtimestamp=1540796958072参数
fy_nr: 下单就金大厦
y_s_y_y: auto
m_b_y_y: ru
请求方式 POST
具体看图分析吧
思路就是你常规的手动操作步骤! 结合开发人员工具 分析访问网址的URL结构 和 一些参数来源,分析status Code状态 如是否重定向以及提交的数据和返回数据进行分析 代码有点问题,给你参考下:
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) import urllib.request
import urllib.parse
import re
text = input('only en-->ch: ')
start = 'https://api.microsofttranslator.com/v2/ajax.svc/TranslateArray?appId=%22T-a9Lzl-SqyqsWg3bIkVJjhFrAsoOSDue5J1E-PRxDO8*%22&texts=[%22'
text = text.replace(' ', '+')
end = '%22]&from=%22en%22&to=%22zh-CHS%22&oncomplete=_mstc2&onerror=_mste2&loc=zh-chs&ctr=&ref=WidgetV3&rgp=2038f2bc'
url = start + text + end
response = urllib.request.urlopen(url)
html = response.read().decode('utf-8')
mod= 'TranslatedText":"([^"]+)"'
target = re.search(mod, html)
print(target.group(1))
页:
[1]