alp*_*per 0 html javascript curl
当我使用curl以检索html页面时,我面对以下消息:
Please turn JavaScript on and reload the page.
我不知道如何处理这个,因此我可以在我的网络浏览器上打开相同的页面.
[问]我怎么能解决这个问题才能使用终端检索html-page的信息?
$ curl http://bsod.pw/
<html>
<head>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function onSubmit(token) {
document.getElementById("recaptcha-form").submit();
}
</script>
</head>
<body>
<div id="recaptcha-loading" style="margin: 0px; padding: 0px; position: fixed; right: 0px; top: 0px; width: 100%; height: 100%; z-index: 30001; opacity: 0.8;">
<p style="position: absolute; color: White; top: 30%; left: 40%;">
<img src="https://250410.selcdn.ru/antiddos/lg.rotating-balls-spinner.gif">
</p>
</div>
<center><noscript><h1 style="text-align:center;color:red;"><strong>Please turn JavaScript on and reload the page.</strong></h1></noscript>
<form id='recaptcha-form' action="/captcha" method="POST">
<button id='submitbutton' style="visibility:hidden;" class="g-recaptcha" data-badge=bottomright data-sitekey="6LcigjgUAAAAACyu9edrmWKmIce8h0kIFQz7iyRo" data-callback='onSubmit'></button>
<script>
window.onload = function(){
document.getElementById('submitbutton').click();
}
</script>
<br/>
</form>
</center>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果你inspect element在网站上(http://bsod.pw/),你可以看到更详细的HTML代码.
感谢您宝贵的时间和帮助.
没有"错误".您使用curl发出GET请求.它会返回一些HTML.HTML恰好包含了浏览器应该加载和执行的JavaScript代码的链接.您的浏览器(已激活JS)可以加载.js脚本并运行它们.这些脚本会生成一些整洁的网页.如果您没有加载链接的脚本,并且不执行它们,那么您不会从页面中获取太多内容.考虑使用合适的无头浏览器(参见下面的示例).
这是一个小例子,应该证明这一点:
<!DOCTYPE html>
<html>
<head>
<title>Source code empty, page full!</title>
</head>
<body>
<div id="fillThis">
<p>Almost nothing there in the source code!</p>
<p>... but inspect this div after JS is executed.</p>
</div>
<script>
var fillThis = document.getElementById("fillThis");
for (i = 0; i<1000; i++) {
var child = document.createElement('p');
child.innerHTML = "tons of content " + i;
fillThis.appendChild(child);
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
只需将其保存为"something.html",然后在浏览器中将其打开即可.当您要求浏览器显示页面源时,这正是您将获得的.但是,当您div通过右键单击它来检查时,它将显示它附加了> 1000个子元素.这些是由JS在您的浏览器中生成的,它们不是以HTML的形式来自服务器.
编辑
我试图使用PhantomJS访问该页面,它几乎可以工作.这是我做的:
#!/bin/bash
cat <<HereDoc > /tmp/phantomjsScript.js
var page = require('webpage').create();
page.open('http://example.com', function(status) {
if(status === "success") {
console.log(page.frameContent);
}
phantom.exit();
});
HereDoc
phantomjs /tmp/phantomjsScript.js
Run Code Online (Sandbox Code Playgroud)
这是一个生成辅助脚本的bash脚本,/tmp然后执行该脚本phantomjs.PhantomJS加载网站,并执行JavaScript.遗憾的是,您链接到的网站受验证码机制保护,无法直接访问,因此上面的示例使用了example.com.如果你可以以某种方式解决验证码,你可能可以使用类似的脚本来加载HTML,运行JS,然后将渲染的DOM转储到控制台.
| 归档时间: |
|
| 查看次数: |
3122 次 |
| 最近记录: |