推荐学习书目
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
0.32D
V2EX  ›  Python

Python 如何模拟 document?

  •  
  •   supersf · Dec 20, 2023 · 2945 views
    This topic created in 895 days ago, the information mentioned may be changed or developed.

    在用爬虫模拟登录的时候,密码是加密过的,引用了一个 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  
       Dec 20, 2023
    建议通过断点拿到原始的加密算法
    shadowShuang
        2
    shadowShuang  
       Dec 20, 2023
    不确定是否可以帮到你,只会些特别基础的爬虫。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
       Dec 20, 2023
    @shadowShuang 我尝试下,感谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5589 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 06:01 · PVG 14:01 · LAX 23:01 · JFK 02:01
    ♥ Do have faith in what you're doing.