Web-Scraping

Web-Scraping(XML)

오늘 일하다가 웹스크랩핑 이란 것을 알게되었고,
간단히 테스트 프로그램을 만들어 보았다.

xml 페이지 읽어오기

package main;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

public class GetCurrencyInfo {

public static void main(String[] args) {
getCurRate();
}

private static void getCurRate() {
try {
// String searchUrl = "http://localhost/eurofxref-daily.xml";
String searchUrl = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(searchUrl);

// xpath 생성
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "/*/*/*/Cube";

NodeList cols = (NodeList) xpath.compile(expression).evaluate(document, XPathConstants.NODESET);

System.out.println("=====================");
System.out.println(cols.item(0).getParentNode().getAttributes().getNamedItem("time").getNodeValue());
System.out.println("=====================");

for (int idx = 0; idx < cols.getLength(); idx++) {
String cur_rate = cols.item(idx).getAttributes().getNamedItem("currency").getNodeValue() + " " + cols.item(idx).getAttributes().getNamedItem("rate").getNodeValue();
System.out.println(cur_rate);
}
} catch (Exception e) {
e.printStackTrace();
}

}
}

구동결과

runnable jar 로 만들어서 돌려본 결과…

D:\dev_git\TestRunnable>java -jar CheckCur_local.jar
=====================
2017-04-05
=====================
USD 1.0678
JPY 118.49
BGN 1.9558
CZK 27.058
DKK 7.4354
...

[참고]
[ksah_web scraping]1
[xPath_doc_tutorial]2 


'프로그래밍 > JAVA' 카테고리의 다른 글

Java Pair 자료구조  (0) 2017.04.14
블로그 이미지

ohnewdev

배워서 남주자

,

이클립스에서 변수명 한번에 바꾸기


package main;
public class Account {
private int balance;
public Account(int i) {
// TODO Auto-generated constructor stub
this.balance = i;
}
public int getBalance() {
// TODO Auto-generated method stub
return this.balance;
}
}


[코드 출처:테스트 주도 개발]


변수명이 i라 money 로 일괄 바꾸고 싶은데… 비록 2개밖에 되지 않지만… 스마트하게 바꿔보자.

shift + alt + r

바꿀 변수 옆에 커서를 둔 상태에서 위와 같이 누르면 같은 변수들이 모두 사각형으로 쌓이면서 바뀐다. 
한번 더 누르면… 대화창도 열린다. 
(블로그 쓰는 재미에 소소한 것도 올려봅니다ㅎ)


블로그 이미지

ohnewdev

배워서 남주자

,

WebLogic 어드민 암호 변경

웹로직콘솔에서 어드민 암호를 바꿨다가 서비스가 다시 올라가지 않는 일이 발생되었다.
[에러로그]

<Authentication denied: Boot identity not valid.
The user name or password or both from the boot identity file (boot.properties) is not valid. The boot identity may hav
e been changed since the boot identity file was created. Please edit and update the boot identity file with the proper v
alues of username and password. The first time the updated boot identity file is used to start the server, these new val
ues are encrypted.>


[조치한 부분]

  • boot.properties 파일 수정
    donmain Home 바로 아래에 boot.properties 파일을 안전하게 작업하기 위해 백업을 해두고, 그 파일을 열어보면 user/password 의 부분이 암호화 되어 있는데, 이 부분을 갱신한 userid/password 로 작성한다. 나중에 재기동할 때 맨 userid/password 는 다시 암호화되어 새로 저장된다. (요 방법, 참 좋은 방법인 것 같다.) 
    그리고, 어드민 콘솔 재시작 한다.
  • domain_home/servers/서비스폴더 재생성
    서비스가 기동될때 해당 폴더에 캐시처럼 서비스 폴더가 생기는데, 기존의 것이 문제가 되었었다. 기존의 것을 백업폴더에 옮겨놓으면 새로 생기는데, 내 경우에는 정상 작동이 되었다.
  • 만약 물리적으로 분리된 환경이라면, boot.properties 를 위와 같은 방법으로 파일을 수정하고 역시 재기동시킨다.


블로그 이미지

ohnewdev

배워서 남주자

,