Python 如何模拟 document?

196 天前
 supersf

在用爬虫模拟登录的时候,密码是加密过的,引用了一个 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; } };

1298 次点击
所在节点    Python
3 条回复
musi
196 天前
建议通过断点拿到原始的加密算法
shadowShuang
196 天前
不确定是否可以帮到你,只会些特别基础的爬虫。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
196 天前
@shadowShuang 我尝试下,感谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1001844

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX