简体   繁体   English

当数据来自JavaScript时,我可以从网页上抓取数据吗?

[英]Can I scrape data from web pages when the data comes from JavaScript?

I'm not exactly sure how to phrase my question but I'll give it my best shot. 我不确定如何表达我的问题,但我会尽力而为。

If I load up a webpage, in the HTML it executes a JavaScript file. 如果我加载网页,则在HTML中执行一个JavaScript文件。 And if I view the page source I can see the source of that JavaScript (though it's not very well formatted and hard to understand). 而且,如果我查看页面源代码,则可以看到该JavaScript的源代码(尽管它的格式不是很好,而且很难理解)。

Is there a way to run the JavaScript from eg Python code, without going through the browser? 有没有一种方法可以通过Python代码运行JavaScript,而无需通过浏览器? ie if I wanted to access a particular function in that JavaScript, is there a clean way to call just that from a Python script, and read the results? 即,如果我想访问该JavaScript中的特定函数,是否有一种干净的方法可以从Python脚本中仅调用该函数并读取结果?

For example... a webpage displays a number that I want access to. 例如,一个网页显示一个我想访问的号码。 It's not in the page source because it's a result from a JavaScript call. 它不在页面源中,因为它是来自JavaScript调用的结果。 Is there a way to call that JavaScript from Python? 有没有办法从Python调用JavaScript?

If you want to scrape a page with javascript in it you've got at least two options: 如果您要抓取带有javascript的页面,则至少有两个选择:

  • Use selenium to load the page and get the node value you're interested in 使用加载页面并获取您感兴趣的节点值
  • Use python-spidermonkey to leverage the javascript right from your python script and get the value you're interested in. 使用python-spidermonkey直接从python脚本中利用javascript并获取您感兴趣的值。

Although your question isn't very clear. 虽然您的问题不是很清楚。 I'm guessing that you are trying to access the javascript console. 我猜您正在尝试访问JavaScript控制台。

In Google Chrome: 在谷歌浏览器中:

  • Press F12 按F12
  • Go to the 'console' tab 转到“控制台”标签

In Mozilla Firefox with Firebug installed: 在安装了Firebug的Mozilla Firefox中:

  • Open Firebug 打开萤火虫
  • Go to the 'console' tab 转到“控制台”标签

From the console you can execute javascript query's (calling functions, accessing variables etc.). 从控制台,您可以执行javascript查询(调用函数,访问变量等)。

I hope this answered your question properly. 我希望这能正确回答您的问题。

I think you are talking about Obfuscate js code 我认为您正在谈论的是模糊的js代码

You can always de-obfuscate them 您可以随时对它们进行模糊处理

There are lots of tools availaible 有很多可用的工具

Here is a addon of mozilla https://addons.mozilla.org/en-us/firefox/addon/javascript-deobfuscator/ 这是mozilla https://addons.mozilla.org/en-us/firefox/addon/javascript-deobfuscator/的附加组件

and an online tool http://jsbeautifier.org/ 和一个在线工具http://jsbeautifier.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 "我如何从网站的 Javascript 内容中抓取数据?" - How can I, scrape data from a Javascript Content of a website? 如何进行 JavaScript 调用以从网站上抓取数据? - How can I make JavaScript calls to scrape data from a website? 如何从无限滚动页面的 DOM 中持续抓取数据? - How to continuously scrape data from the DOM of a page that comes with infinite scrolling? 如何从 JavaScript 网站抓取数据? - How do I scrape data from JavaScript website? 从鼠标悬停弹出窗口中抓取 web 数据 - Scrape web data from mouseover popup 我可以从 highcharts.js 中抓取原始数据吗? - Can I scrape the raw data from highcharts.js? 使用Javascript从元数据中收集信息 - Scrape information from meta data with Javascript 如何使用Scrapy 1.4.0从javascript抓取数据? - How scrape data from javascript with Scrapy 1.4.0? 使用 javascript 将数据从一个域发送到另一个域(我可以访问两个 web 页面) - Sending data from one domain to another using javascript (I have access to the <head> of both web pages) 当我尝试从我网站的其他页面访问它们时,如何从缓存中获取 web 页面并恢复 forms 中的数据? - How to get the web pages from cache and restore data in the forms when i try to reach them from other pages of my site?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM