Java 使用JSoup提取所有课程名称
我是新来的网络抓取生意。我一直在努力从Udacity获取所有课程标题,但不幸的是我没有成功 谁能给我指一下正确的方向吗?先谢谢你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
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
读一下