获取使用密码保护的网站的Jsoup HTML源代码 [英] Getting HTML Source using Jsoup of a password protected website

查看:245
本文介绍了获取使用密码保护的网站的Jsoup HTML源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我试图用Jsoup,具体方法

As the title says, I am trying to use Jsoup, specifically the method

String html = Jsoup.connect(page.getUrl()).get().html(); 

该网站由用户名和密码保护,我有登录凭据,但如果我尝试获取页面的源代码,网址重定向到一个请登录页面。我没有自己的网站(不必直接访问数据库)。此外,我不知道HTTP或JavaScript。在活动中,用户将在网​​页视图导航和登录到这个网站,一旦被登录,我得到的URL,并尝试获取源(用上述方法)。

The website is protected by username and password, and I have the login credentials but if I try to fetch the source of the page, the Url redirects to a "please login" page. I do not own the website (do not have direct access to database). Furthermore, I do not know http or Javascript. In the activity, the user will navigate in a webview and log-in to this website and once they are logged in, I get the URL and try to get the source (using the above method).

总之,我的可以与Jsoup顺利拿到源代码,但URL重定向到一个登录页面。

In summary, I can get the source successfully with Jsoup, but the URL redirects to a login page.

感谢您提前。

推荐答案

您必须登录到使用你的java code中的网站。使用实时HTTP头[火狐插件],查看所有HTTP头并尝试使用你的java code发送这些报头,所以该网站认为,Web浏览器尝试连接到它。

You have to login to the website using your java code. Use live http header[firefox addon] to see all http headers and try to send these headers using your java code, so that the website thinks that a web browser is trying to connect to it.

总之,请尝试使用你的java code模仿浏览器的行为和行动。

In short, try to emulate the browser's behaviour and actions using your java code.

您可以登录使用Jsoup从以下code:

You can login using Jsoup from the following code:

Document doc = Jsoup.connect("http://www.example.com/login.php").data("username", "myUsername", 
"password",   "myPassword").post();

然后再尝试读取页面的HTML

and then try to read the html of the page

这篇关于获取使用密码保护的网站的Jsoup HTML源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆