Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用JSoup提取所有课程名称_Java_Jsoup - Fatal编程技术网

Java 使用JSoup提取所有课程名称

Java 使用JSoup提取所有课程名称,java,jsoup,Java,Jsoup,我是新来的网络抓取生意。我一直在努力从Udacity获取所有课程标题,但不幸的是我没有成功 谁能给我指一下正确的方向吗?先谢谢你 public static void main(String[] args) { // TODO Auto-generated method stub Document doc; try { doc = Jsoup.connect("https://www.udacity.com/courses/all").get

我是新来的网络抓取生意。我一直在努力从Udacity获取所有课程标题,但不幸的是我没有成功

谁能给我指一下正确的方向吗?先谢谢你

public static void main(String[] args) 
{
    // TODO Auto-generated method stub
    Document doc;

    try
    {

        doc = Jsoup.connect("https://www.udacity.com/courses/all").get();


        //Extract Header "1"
        //Element titleWiki = doc.select("h1,h-slim-top").first();

        Elements Contents = doc.select("h3");


        System.out.println(Contents.size());



        for(Element courseTitle:Contents)
            System.out.println("\nCourse Titles " + courseTitle.text());

    }

        catch(IOException e){

        }



    }

}

希望对你有帮助

String url = "https://www.udacity.com/public-api/v0/courses";
Document doc = Jsoup
        .connect(url)
        .referrer("https://www.udacity.com/courses/all")
        .userAgent(
                "Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
        .ignoreContentType(true).get();

String jsonData = doc.body().text();

try {

    JSONObject obj = new JSONObject(jsonData);
    JSONArray courses = obj.getJSONArray("courses");

    for (int i = 0; i < courses.length(); i++) {

        JSONObject course = (JSONObject) courses.get(i);
        String courseName = course.getString("title");
        System.out.println(courseName);
    }

} catch (JSONException e) {

}
stringurl=”https://www.udacity.com/public-api/v0/courses";
文档doc=Jsoup
.connect(url)
.推荐人(”https://www.udacity.com/courses/all")
.用户代理(
“Mozilla/5.0(Windows;U;WindowsNT 5.1;en-US;rv1.8.1.6)Gecko/20070725 Firefox/2.0.0.6”)
.ignoreContentType(true).get();
字符串jsonData=doc.body().text();
试一试{
JSONObject obj=新的JSONObject(jsonData);
JSONArray课程=对象getJSONArray(“课程”);
对于(int i=0;i
读一下