• 爬虫(POST)——有道翻译(有bug)


    工具:python3

    过程:抓包得到有道翻页面的url;复制post请求头,得到headers中的信息;复制post请求的body,得到formdata中的信息。构造post请求,返回响应

    import urllib.request
    
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
        "Content-Type": " application/x-www-form-urlencoded",
        "X-Requested-With": "XMLHttpRequest"
               }
    
    url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule "
    
    key = input("请输入需要翻译的文字:")
    
    formdata = {
        "i": key,
        "from":"AUTO",
        "to":"AUTO",
        "smartresult":"dict",
        "client":"fanyideskweb",
        "salt":"1527240517613",
        "sign":"b6871f33bfa94784d832dddbe9fba785",
        "doctype":"json&version=2.1",
        "keyfrom":"fanyi.web",
        "action":"FY_BY_REALTIME",
        "typoResult":"false"
    }
    
    
    data = urllib.parse.urlencode(formdata)
    data = bytes(data, encoding="utf8")
    print(data)
    request = urllib.request.Request(url, data=data, headers = headers)
    print(request)
    response = urllib.request.urlopen(request)
    print(response.read())

    返回error:50 

    修改url,去掉_o后仍然不能得到正确的信息,,,原来,有道有反爬虫机制!

    哈哈哈哈,刚学爬虫,把这个问题先放一下好啦!

    我很棒棒哦!

  • 相关阅读:
    WEB开发中合理选择图片格式
    Ext.ux.form.LovCombo bug修正
    Ext.grid.PropertyGrid 扩展
    BLOG代码高亮
    Box2D教程1创建碰撞世界
    Box2D教程2鼠标交互
    Box2D教程5碰撞检测
    Box2D教程3刚体绑定外观
    管窥HTML5
    Box2D教程4复杂刚体的复杂外观
  • 原文地址:https://www.cnblogs.com/gaoquanquan/p/9102184.html
Copyright © 2020-2023  润新知