使用Java/Python使用javascript发布http请求?

2024-09-30 22:26:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试连接到http://leya2.eu/。 我试过很多东西。。。问题是在网站上运行脚本。 我确实想用Python或Java来实现它。。。我最后一次尝试的是PhatomJS,但我每次都只得到BlazingFast页面。你知道吗

问题是这个脚本:

var XHR="onload"in new XMLHttpRequest?XMLHttpRequest:XDomainRequest,xhr=new XHR;var ww = $(window).width();xhr.open("GET","/___S___/?rid=CLYVwTkbSONnYzhmsnBo6AhooeCoHsgxayFRarvktEYBIdpcL2aQPVoW7U32QGrh&sid=" + ww +"&d=leya2.eu&tz=1500505915.508",true),xhr.onreadystatechange=function(){if(4==xhr.readyState&&(xhr.status==200)){var t=document.createElement("script");t.type="text/javascript",t.text=xhr.responseText,document.body.appendChild(t)}},xhr.send(null);function wait(){}; setTimeout(wait(),4000);

也许有人有主意了?你知道吗

我的标准脚本是:

from urllib.request import urlopen
from urllib.parse import urlencode

url = 'http://evidence-server.com/?s=login'
response = urlopen(url, urlencode(data).encode("utf-8"))
content = response.read().decode(response.headers.get_content_charset())
print(content)

这一切就在附近:

var page = require("webpage").create(),
    url = "http://leya2.eu/";

function onPageReady() {
    var htmlContent = page.evaluate(function () {
        return document.documentElement.outerHTML;
    });

    console.log(htmlContent);

    phantom.exit();
}
page.open(url, function (status) {
    if (status !== 'success') {
        console.log('Unable to load the address!');
        phantom.exit();
    } else {
        window.setTimeout(function () {
            console.log(htmlContent);
            phantom.exit();
        }, 5000); 
    }
});

Tags: 脚本httpurlresponsevarstatuspagefunction
1条回答
网友
1楼 · 发布于 2024-09-30 22:26:56

下面是访问目标站点的工作脚本。注意一个内置变量page.content

var page = require("webpage").create(),
    url = "http://leya2.eu/";


page.open(url, function (status) {
    if (status !== 'success') {
        console.log('Unable to load the address!');
        phantom.exit();
    } else {
        window.setTimeout(function () {
            page.render("leya2.jpg");
            console.log(page.content);
            phantom.exit();
        }, 10000); 
    }
});

在适用于Windows的PhantomJS 2.5b版上生成this screenshot。你知道吗

相关问题 更多 >