package ds;
import java.io.IOException;
import java.net.URLEncoder;
import org.jsoup.*;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class test
{
public static void main(String[] args)
{
// TODO Auto-generated method stubI
try
{
String str = "한글";
String utf8= URLEncoder.encode(str,"UTF-8");//쿼리문에들어갈 한글인코딩
String url = "http://search.naver.com/search.naver?where=nexearch&query="+utf8+"&display=10&start=1&target=webkr&sm=top_hty&fbm=1&ie=utf8";
&display=10&start=1&target=webkr
Document doc = Jsoup
.connect(url)
.header( //헤더
"Accept",
"image/gif, image/xxbitmap, image/jpeg, image/pjpeg,application/xshockwaveflash, application/vnd.msexcel,application/vnd.mspowerpoint, application/msword, */*").get();
Elements links = doc.getElementsByTag("a"); //a태그 몽땅
for (Element link : links)
{
System.out.println(link.text()); //a태그에 텍스트
System.out.println(link.attr("abs:href")); //a태그 속성 href값
}
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
'프로젝트' 카테고리의 다른 글
웹크롤러.exe 와 실행영상 (0) | 2014.11.27 |
---|---|
jsoup (0) | 2014.11.21 |
Matcher 메서드 사용방법과 그룹 개념이해 (0) | 2014.09.29 |
URL 긁어 오기 (0) | 2014.09.26 |
Http 헤더 정리 (0) | 2014.09.23 |