使用Jsoup爬取互联网信息

public static void parserURLsByPost(){
       try {
           Document doc = Jsoup.connect("http://search.51job.com/jobsearch/search_result.php?fromJs=1&jobarea=0000&district=0000&funtype=0000&industrytype=00&issuedate=9&providesalary=99&keyword=java&keywordtype=2&curr_page=1&lang=c&stype=1&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=01&lonlat=0%2C0&radius=-1&ord_field=0&list_type=0&fromType=14").data("query", "Java")
           .userAgent("Mozilla")
           .cookie("auth", "token")
           .timeout(30000)
           .post();
           Elements link = doc.select("a");
           for (Element element : link) {
               Elements s=element.getElementsByAttributeValue("class", "jobname");
               for (Element element2 : s) {
                  String relHref= element2.attr("href");
                   System.out.println(element2.text());
                   System.out.println(relHref);
            }
              /* Element relSrc = element.attr("class", "jobname"); // == "/"
               if(relSrc.hasClass("jobname")){
               System.out.println(element.text());
               }
              // String linkHref = element.attr("href");
*/               //System.out.println(linkHref);
           }
           //String title = doc.title(); // == "/"
          // String absHref = link.attr("abs:href"); // "http://jsoup.org/"
           //System.out.println(title);
          
       } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
   } 

猜你喜欢

转载自yangfuchao418.iteye.com/blog/763074