자바(Java)/자바 로봇 프로그래밍
[자바 파싱] bet365 devtools에서 소스 복사해서 클립보드에 넣기
xemaker
2024. 7. 25. 13:28
package robot_bbs_insert;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
public class DevToolsHtml {
String URL = "https://aaa.com/";
public void devToolsHtml() throws Exception {
Runtime rt=Runtime.getRuntime();
//IE 실행
String ie="C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe";
Process pro=null;
try {
pro=rt.exec(ie);
pro.waitFor();
}catch(Exception e) {
e.printStackTrace();
}
//Thread.sleep(1000);
Robot robot=new Robot();
//화면최대화
robot.keyPress(KeyEvent.VK_WINDOWS);
robot.keyPress(KeyEvent.VK_UP);
robot.delay(500);
robot.keyRelease(KeyEvent.VK_WINDOWS);
robot.keyRelease(KeyEvent.VK_UP);
robot.delay(500);
//클립보드로 복사
StringSelection data=new StringSelection(URL);
Clipboard clipboard=Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(data, data);
//도메인 입력창에 url 입력(클립보드에 복사 후 붙여넣기)
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.delay(500);
Thread.sleep(5000);
//검사 단축키 ctrl+shift+I
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_I);
robot.delay(500);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_SHIFT);
robot.keyRelease(KeyEvent.VK_I);
Thread.sleep(1000);
robot.delay(500);
//검사창 최대크게
robot.keyPress(KeyEvent.VK_WINDOWS);
robot.keyPress(KeyEvent.VK_UP);
robot.delay(500);
robot.keyRelease(KeyEvent.VK_WINDOWS);
robot.keyRelease(KeyEvent.VK_UP);
robot.delay(1000);
//마우스 요소탭 클릭
robot.mouseMove(153,37);
robot.delay(500);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); //왼쪽 누르기
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); //떼기
robot.delay(200);
Thread.sleep(2000);
//html 태그 클릭
robot.mouseMove(38,80);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); //왼쪽 누르기
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); //떼기
robot.delay(500);
Thread.sleep(2000);
//복사(ctrl+c)
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_C);
robot.delay(500);
robot.keyRelease(KeyEvent.VK_C);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.delay(200);
//dev tools 창 닫기 (alt+f4)
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_F4);
robot.delay(500);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_F4);
robot.delay(200);
//원래 창 닫기 (alt+f4)
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_F4);
robot.delay(500);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_F4);
robot.delay(200);
pro.destroy();
rt.freeMemory();
}
public static void main(String[] args){
System.out.println("시작");
try {
DevToolsHtml dev=new DevToolsHtml();
dev.devToolsHtml();
}catch(Exception e) {
e.printStackTrace();
}
System.out.println("끝");
}
}