Créez un environnement de navigateur pour télécharger nodejs

La commande est la suivante

Démarrez la fenêtre cmd pour exécuter la commande

05a9572f05854078a8bae7d7e74fc5ca.png

 L'attente est terminée

Créer un fichier js

Écrivez le code suivant

74dabe5fc5f84805af7bd1eb35fbfb36.png

 const jsdom=require("jsdom")const {JSDOM}=jsdomconst resourceLoader=new jsdom.ResourceLoader({ userAgent : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, comme Gecko) Chrome/94.0.4606.71 Safari/537.36 Core/1.94.196.400 QQBrowser/11.7.5286.400"});const html="<!DOCTYPE html><p>Bonjour tout le monde</p>";const dom=new JSDOM(html,{ url:"https ://www.endata.com.cn/BoxOffice/BO/Year/index.html", référent :"https://www.endata.com.cn/BoxOffice/BO/Year/index.html", contentType : "text/html", ressource:resourceLoader,});window=global;const params={ location:{ hash: "", hôte: "www.endata.com.cn/", nom d'hôte: "www.endata.com .cn/", href : "https://www.endata.com.cn/BoxOffice/BO/Year/index.html", origine : "https://www.endata.com.cn/BoxOffice/BO/Year/index.html", chemin d'accès : "/", port : "", protocole : "http:", recherche : "" }, navigateur :{ userAgent : "Mozilla/5.0 (Windows NT 10.0 ; Win64; x64) AppleWebKit/537.36 (KHTML, comme Gecko) Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.67", }}//拼接对象Object.assign(global,params)document=dom.window.documentwindow =dom.fenêtre

 Vous pouvez écrire la fonction js ci-dessous

e30e904a84c4468fb10bf2fa19ac8c23.png

 Utilisez Python pour appeler js comme suit

Importer les execjs du module

49738455488249f8a3b58999c173d5ee.png

 

Sinon, vous pouvez l'installer avec pip

Configurer le chemin du package du module

16ea785d60b648ada328fe956beba105.png

 L'image a été bloquée car elle contient des informations sensibles.

Jetez un œil au code et copiez-le pour exécuter le code js

afaa128cca26498c9c67d27a5b717b8e.png

 

Je suppose que tu aimes

Origine blog.csdn.net/qq1278169704/article/details/130397911
conseillé
Classement