날씨 정보를 주기적으로 텍스트로 갖고 오고 싶은데요...

issue00의 이미지

어떤 방법이 있을지........
뾰족하게 이거다라는 느낌이 없는데용....

혹시 도움주실분 계신가요.....

fliers의 이미지

원칙적으로 하면 정보제공업체와 협의하여야 하는 것이 맞을 것 같습니다. 저작권이 있기도 하며, 무단 도용입니다.
하지만 하는 방법은 있습니다.

기상청이나 kweather 같은 곳에서 얻어올 수 있는데,
html으로 보여주는 것은 절적히 파싱을 해주어야 겠지요.

기타 애플릿이나 플래시같은 것으로 보여주는 서비스들은 잘 뒤져보면
날시정보를 가져오는 URL이 있습니다. 찾아내서 가져와가지고
적절히 사용하면 되지요..

뉴스사이트의 뉴스 티커도 분석해서 홈페이지에 넣었었는데, 양심이 찔려서 자진 삭제했었습니다.

issue00의 이미지

html 파싱하는건데.....

제 생각이 맞게 가고 있는지는 모르겠습니다.

html파싱해본적이 없어서.....

잘될까 모르겠네요.....그런데 이게 지금 답으로 옳게 가고 있는걸까용??

항상 깨어있어라 ~~~

맹고이의 이미지

뭘로 만드실지 모르지만 참고하세요.

http://kltp.kldp.org/stories.php?story=01/12/19/4542367

파이썬으로 만들면 간단히 될 것 같은데... ;;

monpetit의 이미지

일반적으로 위키 같은 곳에서 날씨정보를 긁어올 때, 파이썬 등의 스크립트 언어로 html 파싱을 통해 필요한 텍스트만 뽑아오는 방법을 사용하고 있습니다.

impactbar의 이미지

위 허접스크립트를 만들었던 성동호입니다.

너무 허접한것 같아서 자바로 다시 만들어 보았습니다. 허접한건 같습니다.

쉘에서는 sed와 grep으로 만들어서 사이트가 변경되면 끝장이었죠.

이번에는 자바에 내장된 html 파서를 사용해서

각 태그사이의 글을 번호로 각각 카운터 해서 뽑아냅니다.

도움이 되었으면 합니다.

//파일명 HtmlParser.java
//자바 1.4.2에서 테스트됨
//컴파일 javac HtmlParser.java
//사용법 java HtmlParser http://www.kma.go.kr/kma_syn/sfc_now.html [contents number]
//java HtmlParser http://www.kma.go.kr/kma_syn/sfc_now.html 경우 모든 내용을 인덱싱하여 가져옵니다.
//java HtmlParser http://www.kma.go.kr/kma_syn/sfc_now.html 706 하면 "의성" 만 가져옵니다.
//사이트가 변경되도 contents number만 바꿔주면 됩니다.
//만든이 성동호(darkeye엣chollian.net) impactbar in kldp

import javax.swing.text.html.*;
import javax.swing.text.html.parser.*;
import java.io.*;
import java.net.*;

public class HtmlParser {

	int contentCount = 0;
	int targetCount = 0;
	
	public HtmlParser() {
	}
	
	public HtmlParser(int wantCount) {
		this.targetCount = wantCount;
	}
	
	private class CallbackHandler extends HTMLEditorKit.ParserCallback {

		public void handleText(char[] data, int pos) {
			contentCount++;
			if(contentCount == targetCount){
				System.out.println(data);
			}
		}
		
	}
		
	private class CallbackHandlerAll extends HTMLEditorKit.ParserCallback {
	
		public void handleText(char[] data, int pos) {
			contentCount++;
			System.out.print(contentCount + " : ");
			System.out.println(data);
		}
	}

	public void getHtmlAll(String inURL) {
		try {

			URL url = new URL(inURL);
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			InputStreamReader reader = new InputStreamReader(conn.getInputStream());
			new ParserDelegator().parse(reader, new CallbackHandlerAll(), true);
			conn.disconnect();

		} catch (Exception e) {

			e.printStackTrace();

		}
	}
	
	public void getHtml(String inURL) {
			try {

				URL url = new URL(inURL);
				HttpURLConnection conn = (HttpURLConnection) url.openConnection();
				InputStreamReader reader = new InputStreamReader(conn.getInputStream());
				new ParserDelegator().parse(reader, new CallbackHandler(), true);
				conn.disconnect();

			} catch (Exception e) {

				e.printStackTrace();

			}
	}
		
	public static void main(String[] args) throws IOException {
		if (args.length < 1) {
			System.out.println("Usage: java HtmlParser URL [want contents number]");
			System.exit(0);
		}else if(args.length >= 2){
			try{
				Integer.parseInt(args[1]);
			}catch(Exception e){
				e.printStackTrace();
				System.out.println("Usage: java HtmlParser URL [want contents number]");
				System.exit(0);
			}
			
			HtmlParser parser = new HtmlParser(Integer.parseInt(args[1]));
			parser.getHtml(args[0]);
			 
		}else{
			HtmlParser parser = new HtmlParser();
			parser.getHtmlAll(args[0]); 
		}
		
		
	}
}
issue00의 이미지

모든 답변 감사드립니다.
많은 도움이 되었습니다.

성동호님?? 그런데 제가 자바를 몰라서...ㅡ.ㅡ;;
파이썬도....ㅡ.ㅡ;;

html을 스크립트로 파서하는걸 맹글어야겠네요...
필요한 텍스트만 뽑는게 필요합니다.

아 ~~ 눈이 아파온다아.........

항상 깨어있어라 ~~~

monpetit의 이미지

C로 하실 계획이라면 libxml2도 html 파서를 지원하죠 아마?

hados의 이미지

www.kweather.co.kr 에 가보면

날씨정보창 이란 서비스를 합니다

플래쉬로 만들어진 건데

특정 지역(예를 들면 서울...대구...이런 식으로)의 날씨를

알려주는 플래쉬 링크를 제공합니다

그 링크만 복사해서 홈페이지의 html 에 붙여도 괜찮더라구요

원하시는 만큼의 정보를 볼 수 있을지는 모르겠지만

참고하세요....

hermit의 이미지

http://www.nalsee.com

사이트에서 지난 달까지는 배너가 안 떴는데 이번 달 부터 배너가 뜹니다. -_- 아무래도 저도 기상청 웹페이지 파싱을 해야겠군요...... ;)

2006년 1월 28일만 보고 산다 -_-;

ai의 이미지

물론 자신의 손에 익숙한 언어가 가장 좋지만, 아마도 perl 은 이런 작업을 위해 존재하는지도 모르는 언어라고 생각합니다. LWP, HTML::TokeParser 를 찾아보세요. perlre 익숙하다면 LWP 만으로도 충분합니다.

http://perldoc.com
http://cpan.org

War doesnt determine whos right, just whos left.

beta의 이미지

기상청에 xml 같은 서비스를 요청해 보는것은 어떨까요?
많은 사람이 쓸꺼 같은데.. 서버 폭주하남? --;

발 담갔다. 이제 익숙해 지는길만이..

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.