鱼C论坛

 找回密码
 立即注册
查看: 3021|回复: 4

新手求助 爬虫 求思路

[复制链接]
发表于 2018-10-28 21:36:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
求教    爬取 www74.woaifanyi.com 的翻译结果    求助诸位大神   不想给代码  哪怕给个思路也行   
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-10-29 15:14:01 | 显示全部楼层
我看了一下接口地址  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


具体看图分析吧

WX20181029-151315.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-10-29 17:22:33 | 显示全部楼层
思路就是你常规的手动操作步骤! 结合开发人员工具 分析访问网址的URL结构 和 一些参数来源,分析status Code状态 如是否重定向以及提交的数据和返回数据进行分析
1.png
2.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-10-29 17:46:46 | 显示全部楼层
代码有点问题,给你参考下:
  1. import urllib.request
  2. import urllib.parse
  3. import time as t
  4. import json
  5. import re

  6. def timestamp():
  7.     str1 = t.time() * 1000
  8.     str1 = str(int(str1))
  9.     return str1

  10. url = 'https://www74.woaifanyi.com/web_system/ilovetranslation_com/wwwroot/key/baidu/save/?ajaxtimestamp='
  11. #url_2 = 'https://www74.woaifanyi.com/web_system/ilovetranslation_com/wwwroot/key/google/save/?ajaxtimestamp='

  12. url = url + timestamp()

  13. data = {
  14.     'fy_nr' : 'Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串、数字、元组等其他容器模型',
  15.     'y_s_y_y' : 'zh',
  16.     'm_b_y_y' : 'en'
  17.     }
  18. #data_2 = {
  19. #    'fy_nr' : 'Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串、数字、元组等其他容器模型',
  20. #    'y_s_y_y' : 'zh-CN',
  21. #   'm_b_y_y' : 'en'
  22. #    }

  23. data = urllib.parse.urlencode(data).encode('utf-8')

  24. response = urllib.request.urlopen(url, data)
  25. html = response.read().decode('utf-8')

  26. new_data = {'hhid' : html.split('"')[-2]}
  27. new_data = urllib.parse.urlencode(new_data).encode('utf-8')

  28. print('Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串、数字、元组等其他容器模型')
  29. print('waiting...')
  30. while True:
  31.     url = 'https://www74.woaifanyi.com/web_system/ilovetranslation_com/wwwroot/key/baidu/get/?ajaxtimestamp='
  32.     url = url + timestamp()
  33.    
  34.     response = urllib.request.urlopen(url, new_data)
  35.     html = response.read().decode('utf-8')
  36.     if html[-3] == '2':
  37.         mod  = '<p>([^"]+)<'
  38.         target = re.search(mod, html)
  39.         print(target.group(1))
  40.         break
  41.     t.sleep(0.1)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-10-29 17:47:39 | 显示全部楼层
  1. import urllib.request
  2. import urllib.parse
  3. import re

  4. text = input('only en-->ch: ')

  5. start = 'https://api.microsofttranslator.com/v2/ajax.svc/TranslateArray?appId=%22T-a9Lzl-SqyqsWg3bIkVJjhFrAsoOSDue5J1E-PRxDO8*%22&texts=[%22'

  6. text = text.replace(' ', '+')
  7. end = '%22]&from=%22en%22&to=%22zh-CHS%22&oncomplete=_mstc2&onerror=_mste2&loc=zh-chs&ctr=&ref=WidgetV3&rgp=2038f2bc'
  8. url = start + text + end

  9. response = urllib.request.urlopen(url)
  10. html = response.read().decode('utf-8')

  11. mod  = 'TranslatedText":"([^"]+)"'
  12. target = re.search(mod, html)
  13. print(target.group(1))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-22 20:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表