V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
supersf
V2EX  ›  Python

Python 如何模拟 document?

  •  
  •   supersf · 134 天前 · 1239 次点击
    这是一个创建于 134 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在用爬虫模拟登录的时候,密码是加密过的,引用了一个 js 文件(已被 ob 混淆)。 js 的调用中 var params = {keyInfo: code, obj: document.getElementById("password"), };
    dataEncode = new enhance(params); 加密后的密码为 dataEncode.getEncrypt()

    目前是使用 selenium 填入 password 的值,然后取 dataEncode.getEncrypt()。 求教下是否可以使用 execjs 等实现呢。 自己模拟一个 document ? var document = { getElementById: function(id) { if (id === 'txtpsd') { return { id: 'txtpsd', value: '#{user_input}' }; // 使用 Ruby 变量赋值 } return null; } };

    musi
        1
    musi  
       134 天前
    建议通过断点拿到原始的加密算法
    shadowShuang
        2
    shadowShuang  
       134 天前
    不确定是否可以帮到你,只会些特别基础的爬虫。selenium 和 execjs 不太知道怎么结合着使用。但是模拟 document 我之前倒是遇到过。
    // window = {}; 这是最一开始我模拟 dom ,后来搜了下,有别人做过模拟 jsdom 。
    const jsdom = require("jsdom");
    const { TextEncoder, TextDecoder } = require("util");
    const {JSDOM} = jsdom;
    const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>');

    window = dom.window
    window.TextEncoder = TextEncoder;
    window.TextDecoder = TextDecoder;

    https://github.com/jsdom/jsdom
    supersf
        3
    supersf  
    OP
       134 天前
    @shadowShuang 我尝试下,感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2282 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:23 · PVG 14:23 · LAX 23:23 · JFK 02:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.