我可以用python登录网页(aspx),但用JSoup不能

2024-05-08 14:05:20 发布

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

import requests as rq

url = "https://ogrotomasyon.uludag.edu.tr/login.aspx?un="
data = { "__EVENTTARGET" : "", "__EVENTARGUMENT" : "",
        "__VIEWSTATE" : "",
        "__VIEWSTATEGENERATOR" : "C2EE9ABB",
        "__EVENTVALIDATION" : "",
        "un":"USERNAME", "pw":"PASSWORD", "ok22": "Giriş"}

s = rq.Session()
a = s.get(url, verify=0)
print(a.text)
d1 = input()
d2 = input()
data["__VIEWSTATE"] = d1
data["__EVENTVALIDATION"] = d2
a = s.post(url, data=data, verify=0)
s.get(a.url)
print(a.url)

我可以用这个代码登录系统,当我真正复制\uu VIEWSTATE和\uu EVENTVALIDATION时。你知道吗

小心:我正在使用一个会话。如果我用的只是rq.获取(“URL”)'我无法登录。我必须使用一个而且总是相同的会话

public static void main(String[] args) {
    try {
        Connection.Response first = Jsoup.connect("https://ogrotomasyon.uludag.edu.tr/login.aspx")
                .validateTLSCertificates(false)
                .method(Connection.Method.GET)
                .execute();


        Elements form = first.parse().select("form");
        Elements inputs = form.select("input");

        System.out.println(inputs.get(0).id() + " " + inputs.get(0).val());
        System.out.println(inputs.get(1).id() + " " + inputs.get(1).val());
        System.out.println(inputs.get(2).id() + " " + inputs.get(2).val());
        System.out.println(inputs.get(3).id() + " " + inputs.get(3).val());
        System.out.println(inputs.get(4).id() + " " + inputs.get(4).val());
        System.out.println(inputs.get(7).id() + " " + inputs.get(7).val());



        Document second = Jsoup.connect("https://ogrotomasyon.uludag.edu.tr/login.aspx")
                .validateTLSCertificates(false)
               .data(inputs.get(0).id(), inputs.get(0).val())
               .data(inputs.get(1).id(), inputs.get(1).val())
               .data(inputs.get(2).id(), inputs.get(2).val())
               .data(inputs.get(3).id(), inputs.get(3).val())
               .data(inputs.get(4).id(), inputs.get(4).val())
               .data("un", "USERNAME")
               .data("pw", "PASSWORD")
               .data(inputs.get(7).id(), inputs.get(7).val())
               .post();
        System.out.println(second.text());

    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

但我不能用这个密码登录。事实上有时候我可以,但很少时候它“抛出java.net.UnknownHostException““

如何通过第二个代码连接?你知道吗


Tags: httpsidurldatagetvaloutsystem