获取网页的源代码。 [英] Getting the source code of a webpage.

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

问题描述

大家好。



我正在构建一个收集课程信息的应用程序,所以我需要访问coursera.org中的一些信息,我需要访问这个来自我的java代码的信息所以我用jsoup来做那个。



当我在firefox浏览器中显示源代码时我没有得到html代码但是我获取一些javascript代码,我无法从中获取所需的文本信息。



使用jsoup获取此信息:



String url =https://www.coursera.org/learn/machine-learning;

文档doc = Jsoup.connect(url).get();

System.out.println(doc.text());



收到此消息:



请使用启用了JavaScript的amodern浏览器来使用Coursera。



所以无论如何都要查看源代码或使用jsoup获取它。



请给予任何帮助。



提前致谢。

Hello every one.

I am building an application which collects info about courses, so I need to access some info in coursera.org, I need to acces this info from my java code so I use jsoup to do that.

When I show the source code in the firefox browser I don't get the html code but I get some javascript code and I can't get the textual info I need from it.

Using jsoup to get this info:

String url ="https://www.coursera.org/learn/machine-learning";
Document doc = Jsoup.connect(url).get();
System.out.println(doc.text());

I get this message:

Please use amodern browser with JavaScript enabled to use Coursera.

So is there anyway to view the source code or get it using jsoup.

Please, any help would be appreciated.

Thanks in advance.

推荐答案

请参阅我对该问题的评论。这里解释了在浏览器中禁用JavaScript时用于处理脚本的技术:

http://www.w3.org/TR/2011/WD-html5-author-20110705/the-noscript-element.html [ ^ ],

https://www.w3.org/wiki/HTML/Elements/noscript [ ^ ]。



这与页面的源代码无关。您总是在客户端获得实际的源代码。



-SA
Please see my comment to the question. The techniques used to handle scripts when JavaScript is disabled in the browser are explained here:
http://www.w3.org/TR/2011/WD-html5-author-20110705/the-noscript-element.html[^],
https://www.w3.org/wiki/HTML/Elements/noscript[^].

This is not related to the source code of the page. You always get an actual source code on the client side.

—SA


谢谢对于你的回答,我尝试使用你的评论来解决这个问题,但直到现在我都没有做到这一点。



但我使用coursera API解决了我的问题:



https://tech.coursera.org/app-platform/catalog / [ ^ ]



我可以使用此API中提供的URL获取任何文本信息。
Thank you for your answer, I tried to solve that using your comment but until now I coupdn't.

But I solved my problem using the coursera API:

https://tech.coursera.org/app-platform/catalog/[^]

Where I can get to any text info using URLs provided in this API.


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

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