김승훈

update main

...@@ -5,56 +5,57 @@ var JASON = require('jason') ...@@ -5,56 +5,57 @@ var JASON = require('jason')
5 const {Builder, By, Key, until} = require('selenium-webdriver'); 5 const {Builder, By, Key, until} = require('selenium-webdriver');
6 var iconv = require('iconv-lite') 6 var iconv = require('iconv-lite')
7 7
8 -var driver = new webdriver.Builder(). 8 +module.exports = {
9 - withCapabilities(webdriver.Capabilities.chrome()). 9 + search_onairanddate: function(driver,string) {
10 - build(); 10 + let url1 = "https://search.naver.com/search.naver?sm=top_hty&fbm=1&ie=utf8&query=" + string
11 - let url1 = "https://search.naver.com/search.naver?sm=top_hty&fbm=1&ie=utf8&query=%EB%9F%B0%EB%8B%9D%EB%A7%A8"
12 - driver
13 - .get(url1).then(() => {
14 driver 11 driver
15 - .findElements(webdriver.By.className('brcs_detail')) 12 + .get(url1).then(() => {
16 - .then(broad_info => { 13 + driver
17 - broad_info[0].findElement(webdriver.By.tagName('dl')) 14 + .findElements(webdriver.By.className('brcs_detail'))
18 - .then(more_data => { 15 + .then(broad_info => {
19 - more_data.findElement(webdriver.By.tagName('dd')) 16 + broad_info[0].findElement(webdriver.By.tagName('dl'))
20 - .then(one_line => { 17 + .then(more_data => {
21 - one_line.findElement(webdriver.By.className("inline")) 18 + more_data.findElement(webdriver.By.tagName('dd'))
22 - .then(isbroad => { 19 + .then(one_line => {
23 - isbroad.getText() 20 + one_line.findElement(webdriver.By.className("inline"))
24 - .then(isbroad_string => { 21 + .then(isbroad => {
25 - console.log(isbroad_string) 22 + isbroad.getText()
26 - broadcasting=isbroad_string.substring(0,4) 23 + .then(isbroad_string => {
27 - isbroad = isbroad_string.substring(18,21) 24 + console.log(isbroad_string)
28 - br_date = isbroad_string.substring(23,24) 25 + broadcasting=isbroad_string.substring(0,4)
29 - br_date = br_date + "요일" 26 + isbroad = isbroad_string.substring(18,21)
30 - br_time = isbroad_string.substring(26,34) 27 + br_date = isbroad_string.substring(23,24)
28 + br_date = br_date + "요일"
29 + br_time = isbroad_string.substring(26,34)
31 30
32 - console.log(broadcasting,isbroad,br_date,br_time) 31 + console.log(broadcasting,isbroad,br_date,br_time)
33 - if(isbroad == "방영중") { 32 + if(isbroad == "방영중") {
34 - driver.findElement(webdriver.By.id('nx_query')).clear().then(( )=> { 33 + driver.findElement(webdriver.By.id('nx_query')).clear().then(( )=> {
35 - //var buf = iconv.encode("편성표", "euc-kr") 34 + //var buf = iconv.encode("편성표", "euc-kr")
36 - //console.log(buf) 35 + //console.log(buf)
37 - //var encodestr=''; 36 + //var encodestr='';
38 - //for(var i=0; i<buf.length;i++) { 37 + //for(var i=0; i<buf.length;i++) {
39 - // encodestr+='%'+buf[i].toString('16') 38 + // encodestr+='%'+buf[i].toString('16')
40 - // } 39 + // }
41 - //encodestr = encodestr.toUpperCase(); 40 + //encodestr = encodestr.toUpperCase();
42 - //console.log(iconv.encode(encodestr, 'EUC-KR').toString()) 41 + //console.log(iconv.encode(encodestr, 'EUC-KR').toString())
43 - //console.log(encodestr) 42 + //console.log(encodestr)
44 - var buf = iconv.encode('편성표','euckr') 43 + //var buf = iconv.encode('편성표','euckr')
45 - var param = buf.toString('binary') 44 + //var param = buf.toString('binary')
46 - console.log(param) 45 + //console.log(param)
47 - driver.findElement(webdriver.By.id('nx_query')).sendKeys(broadcasting,br_date,param) 46 + //driver.findElement(webdriver.By.id('nx_query')).sendKeys(broadcasting,br_date,param)
48 - driver.findElement(webdriver.By.className('spnew ico_search')).click() 47 + //driver.findElement(webdriver.By.className('spnew ico_search')).click()
49 - }) 48 + })
50 -
51 - }
52 - else {
53 49
54 - } 50 + }
51 + else {
52 +
53 + }
54 + })
55 }) 55 })
56 }) 56 })
57 }) 57 })
58 }) 58 })
59 }) 59 })
60 - }) 60 + }
61 +}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -8,70 +8,67 @@ const screen = { ...@@ -8,70 +8,67 @@ const screen = {
8 }; 8 };
9 var a=0 9 var a=0
10 var breaktheloop = false 10 var breaktheloop = false
11 -var driver = new webdriver.Builder(). 11 +module.exports = {
12 - withCapabilities(webdriver.Capabilities.chrome()). 12 + search_broadcasting : function(driver,url) {
13 - build(); 13 + driver
14 - 14 + .get(url)
15 - 15 + .then(() => {
16 - 16 + driver.findElement(webdriver.By.id('pagination_76'))
17 - let url = 'https://people.search.naver.com/search.naver?where=nexearch&query=%EC%9C%A0%EC%9E%AC%EC%84%9D&sm=tab_etc&ie=utf8&key=PeopleService&os=94702'; 17 + .then ( paginationBtn => {
18 - driver 18 + paginationBtn.findElements(webdriver.By.className('bt_next'))
19 - .get(url) 19 + .then(Btn_next => {
20 - .then(() => { 20 + driver.findElement(webdriver.By.id('listUI_76'))
21 - driver.findElement(webdriver.By.id('pagination_76')) 21 + .then(contentsUI => {
22 - .then ( paginationBtn => { 22 + contentsUI.findElements(webdriver.By.tagName('li'))
23 - paginationBtn.findElements(webdriver.By.className('bt_next')) 23 + .then(elems => {
24 - .then(Btn_next => { 24 + elems.forEach(elem => {
25 - driver.findElement(webdriver.By.id('listUI_76')) 25 + elem.getText()
26 - .then(contentsUI => { 26 + .then(text => {
27 - contentsUI.findElements(webdriver.By.tagName('li')) 27 + console.log(text)
28 - .then(elems => { 28 + })
29 - elems.forEach(elem => {
30 - elem.getText()
31 - .then(text => {
32 - console.log(text)
33 }) 29 })
34 }) 30 })
35 - }) 31 + clickandget()
36 - clickandget() 32 + function clickandget() {
37 - function clickandget() { 33 + Btn_next[0].isDisplayed().then(function(state) {
38 - Btn_next[0].isDisplayed().then(function(state) { 34 + if(state) {
39 - if(state) { 35 + Btn_next[0].click()
40 - Btn_next[0].click() 36 + sleep(500).then(()=> {
41 - sleep(500).then(()=> { 37 + contentsUI.findElements(webdriver.By.tagName('li'))
42 - contentsUI.findElements(webdriver.By.tagName('li')) 38 + .then(elems => {
43 - .then(elems => { 39 + elems.forEach(elem => {
44 - elems.forEach(elem => { 40 + elem.getText()
45 - elem.getText() 41 + .then(text => {
46 - .then(text => { 42 + console.log(text)
47 - console.log(text) 43 + })
48 }) 44 })
49 }) 45 })
50 }) 46 })
51 - }) 47 + }
52 - } 48 + else {
53 - else { 49 + console.log(state)
54 - console.log(state) 50 + }
55 - } 51 + })
56 - }) 52 + }
57 - } 53 + })
58 }) 54 })
59 }) 55 })
60 }) 56 })
61 - })
62 57
63 - function getContentsandClickNext(callback) { 58 + function getContentsandClickNext(callback) {
64 - driver.findElement(webdriver.By.id('listUI_76')) 59 + driver.findElement(webdriver.By.id('listUI_76'))
65 - .then(contentsUI => { 60 + .then(contentsUI => {
66 - contentsUI.findElements(webdriver.By.tagName('li')) 61 + contentsUI.findElements(webdriver.By.tagName('li'))
67 - .then(elems => { 62 + .then(elems => {
68 - elems.forEach(elem => { 63 + elems.forEach(elem => {
69 - elem.getTex 64 + elem.getTex
65 + })
70 }) 66 })
71 }) 67 })
72 - }) 68 + }
73 - }
74 69
75 - function sleep (time) {
76 - return new Promise((resolve) => setTimeout(resolve, time));
77 - }
...\ No newline at end of file ...\ No newline at end of file
70 + function sleep (time) {
71 + return new Promise((resolve) => setTimeout(resolve, time));
72 + }
73 + }
74 +}
...\ No newline at end of file ...\ No newline at end of file
......
1 var async = require('async'); 1 var async = require('async');
2 var webdriver = require('selenium-webdriver'); 2 var webdriver = require('selenium-webdriver');
3 -var options = {desiredCapabilities: {browserName: 'chrome'}}; 3 +//var options = {desiredCapabilities: {browserName: 'chrome'}};
4 -var JASON = require('jason') 4 +var chrome = require('selenium-webdriver/chrome')
5 -const {Builder, By, Key, until} = require('selenium-webdriver'); 5 +var Options = new chrome.Options();
6 - 6 +Options.addArguments('headless')
7 +Options.addArguments('disable-gpu')
8 +//var JASON = require('jason')
9 +//var util = require('util')
10 +//var EventEmitter = require('events')
11 +var check = 0
12 +var testStartRunTime = 0;
13 +var testruntime = 0;
7 14
15 +const {Builder, By, Key, until} = require('selenium-webdriver');
8 16
9 -var ajason = new Object() 17 +var next_link_list = []
10 -var aname = [] 18 +var src_list = []
11 -var asrc=[] 19 +var text_list = []
12 -var alink=[] 20 +var return_list = []
13 -var driver = new webdriver.Builder(). 21 +module.exports = {
14 -withCapabilities(webdriver.Capabilities.chrome()). 22 + first_search : function(driver,string) {
15 -build(); 23 +
16 -let url1 = "https://people.search.naver.com/search.naver?sm=tab_hty&where=nexearch&query=%EC%9C%A0%EC%9E%AC%EC%84%9D&ie=utf8&x=0&y=0" 24 + function testRunTimer() {
17 -var driver_1 = new webdriver.Builder(). 25 + var today = new Date(); // 현재시간 얻기
18 -withCapabilities(webdriver.Capabilities.chrome()). 26 + var runTime = today.getTime(); // 밀리세컨드 ( 1970/01/01 부터 현재까지의 시간을 밀리세컨드로 나타냄 )
19 -build(); 27 + var rtn = 0;
20 - 28 +
21 -driver 29 + if (testStartRunTime == 0) {
22 -.get(url1).then(() => { 30 + testStartRunTime = runTime;
23 - driver 31 + } else {
24 - .findElements(webdriver.By.className('result_profile')) 32 + rtn = (runTime - testStartRunTime) / 1000;
25 - .then(whoclasses=> { 33 + testStartRunTime = 0;
26 - whoclasses.forEach(whoclass => { 34 + }
27 - whoclass.findElements(webdriver.By.className('thmb')) 35 + return rtn;
28 - .then(img_thmbs => { 36 + }
29 - img_thmbs.forEach(img_thmb => { 37 + let url1 = "https://people.search.naver.com/search.naver?sm=tab_hty&where=nexearch&query="+string+"&ie=utf8&x=0&y=0"
30 - img_thmb.findElements(webdriver.By.className('thmb_img')).then(img_src => { 38 + driver
31 - 39 + .get(url1).then(() => {
32 - img_src[0].getAttribute("src") 40 + testRunTimer()
33 - .then(src => { 41 + driver
34 - asrc.push(src) 42 + .findElements(webdriver.By.className('result_profile'))
35 - console.log(src) 43 + .then(profiles => {
36 - }).then(() => { 44 + profiles.forEach(profile => {
37 - console.log(asrc) 45 + profile.findElements(webdriver.By.className('thmb'))
38 - }) 46 + .then(links=> {
39 - }) 47 + links.forEach(link => {
40 - }) 48 + link.getAttribute('href')
41 - whoclass.findElements(webdriver.By.tagName("strong")) 49 + .then(next_link => {
42 - .then(name_temp => { 50 + profile.findElements(webdriver.By.className('thmb_img'))
43 - name_temp[0].getText().then(name => { 51 + .then((imgs) => {
44 - aname.push(name) 52 + imgs.forEach(img => {
45 - }) 53 + img.getAttribute('src')
46 - }) 54 + .then(src => {
47 - }) 55 + profile.findElements(webdriver.By.className('who'))
48 - whoclass.findElements(webdriver.By.className('who')) 56 + .then(whos => {
49 - .then(who => { 57 + whos.forEach(who => {
50 - who[0].findElements(webdriver.By.className('name')) 58 + who.getText()
51 - .then(findname => { 59 + .then(text => {
52 - findname[0].getAttribute("href") 60 + next_link_list.push(next_link)
53 - .then(link => { 61 + src_list.push(src)
54 - alink.push(link) 62 + text_list.push(text)
55 - }).then(() => { 63 + testruntime += testRunTimer()
56 - driver_1.get(alink[0]).then(() => { 64 + console.log(testruntime)
57 - driver_1 65 + setTimeout(function() {
58 - .findElement(webdriver.By.id('pagination_76')) 66 + check++;
59 - .then(paginationBtn => { 67 + if(check==1) {
60 - paginationBtn.findElements(webdriver.By.className('bt_next')) 68 + return_list.push(next_link_list)
61 - .then(elemsBtn => { 69 + return_list.push(src_list)
62 - var cnt = 1; 70 + return_list.push(text_list)
63 - 71 + console.log(testruntime)
64 - function getContentsAndClickNext (callback) { 72 + setTimeout(function() {
65 - console.log('higetcontests', cnt); 73 + console.log(return_list)
66 - cnt++; 74 + return return_list
67 - driver_1 75 + },500)
68 - .findElement(webdriver.By.id('listUI_76')) 76 + }
69 - .then(contentsUI => { 77 + },testruntime+1000)
70 - contentsUI
71 - .findElements(webdriver.By.tagName('li'))
72 - .then(elems => {
73 - elems.forEach(elem => {
74 - elem
75 - .getText()
76 - .then(text => {
77 - console.log(text);
78 - // 내 추측 : stale해지면, boolean 값으로 driver 어딘가에 true설정되는것 같아
79 - // wait이라는 함수를 써서, 이게 false 가 될 때까지 기다린 다음에 getText()를 해.
80 - // ok?
81 - })
82 - .catch(error => {
83 - // 문제가 있으면 이곳을 의심해볼것! 변수 error를 체크해보기!
84 - // console.log('really?? exception!');
85 - })
86 - })
87 -
88 - elemsBtn[0].click();
89 -
90 - sleep(50).then(() => {
91 - // Do something after the sleep!
92 - });
93 - callback();
94 }) 78 })
95 - .catch(error => { 79 + })
96 - console.log("asdfasdf!!', e");
97 - })
98 - })
99 - .catch(error => {
100 - console.log('fuck!@#', error);
101 }) 80 })
102 - } 81 + })
103 - 82 + })
104 - async.whilst(
105 - function() {
106 - console.log('whilist result', cnt < 5);
107 - return cnt < 5;
108 - },
109 - getContentsAndClickNext,
110 - function(e) {
111 - console.log('Exception', e)
112 - }
113 - );
114 }) 83 })
115 - .catch(error => {
116 - console.log('Exception 4444', error);
117 - }); // 다음 컨텐츠로 가는 버튼(2개임. 하나는 평소용 두번째는 더이상 갈 페이지가 없을 때 쓰는 버튼)
118 }) 84 })
119 - .catch(error => { 85 + })
120 - console.log('Exception 555', error);
121 - }); // 방송 컨텐츠 페이지네이션 버튼
122 -
123 -
124 - // sleep time expects milliseconds
125 - function sleep (time) {
126 - return new Promise((resolve) => setTimeout(resolve, time));
127 - }
128 -
129 - // Usage!
130 - sleep(8000).then(() => {
131 - // Do something after the sleep!
132 - });
133 -
134 - });
135 }) 86 })
136 }) 87 })
137 }) 88 })
138 }) 89 })
90 + }
91 +}
139 92
140 - })
141 -})
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -5,29 +5,30 @@ var JASON = require('jason') ...@@ -5,29 +5,30 @@ var JASON = require('jason')
5 const {Builder, By, Key, until} = require('selenium-webdriver'); 5 const {Builder, By, Key, until} = require('selenium-webdriver');
6 var iconv = require('iconv-lite') 6 var iconv = require('iconv-lite')
7 7
8 -var findtitle = "런닝맨" 8 +
9 -var driver = new webdriver.Builder(). 9 +module.exports = {
10 - withCapabilities(webdriver.Capabilities.chrome()). 10 + search_broadcasting_time : function(driver,broadcast,day,findtitle) {
11 - build(); 11 + let url1 = "https://search.naver.com/search.naver?sm=top_hty&fbm=0&ie=utf8&query="+broadcast+"+"+day+"+편성표"
12 - let url1 = "https://search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=SBS+%EC%9D%BC%EC%9A%94%EC%9D%BC+%ED%8E%B8%EC%84%B1%ED%91%9C&oquery=SBS+%EC%9B%94%EC%9A%94%EC%9D%BC+%ED%8E%B8%EC%84%B1%ED%91%9C&tqi=UsDTSlpySD0ssv33OfVssssssXK-499490"
13 - driver
14 - .get(url1).then(() => {
15 driver 12 driver
16 - .findElements(webdriver.By.className('cont_inner type_day _scheduleArea')) 13 + .get(url1).then(() => {
17 - .then(contentsearch_section=> { 14 + driver
18 - contentsearch_section[0].findElements(webdriver.By.tagName('tbody')) 15 + .findElements(webdriver.By.className('cont_inner type_day _scheduleArea'))
19 - .then(tbody => { 16 + .then(contentsearch_section=> {
20 - tbody[0].findElements(webdriver.By.tagName('tr')) 17 + contentsearch_section[0].findElements(webdriver.By.tagName('tbody'))
21 - .then(trs => { 18 + .then(tbody => {
22 - trs.forEach(tr => { 19 + tbody[0].findElements(webdriver.By.tagName('tr'))
23 - tr.getText() 20 + .then(trs => {
24 - .then(content => { 21 + trs.forEach(tr => {
25 - if(content.indexOf(findtitle) != -1) { 22 + tr.getText()
26 - console.log(content) 23 + .then(content => {
27 - } 24 + if(content.indexOf(findtitle) != -1) {
25 + console.log(content)
26 + }
27 + })
28 }) 28 })
29 }) 29 })
30 }) 30 })
31 }) 31 })
32 }) 32 })
33 - }) 33 + }
34 +}
...\ No newline at end of file ...\ No newline at end of file
......
1 +var async = require('async');
2 +var webdriver = require('selenium-webdriver');
3 +//var options = {desiredCapabilities: {browserName: 'chrome'}};
4 +var chrome = require('selenium-webdriver/chrome')
5 +var Options = new chrome.Options();
6 +Options.addArguments('headless')
7 +Options.addArguments('disable-gpu')
8 +var JASON = require('jason')
9 +const test1 = require('./crawling_samename')
10 +const test2 = require('./crawling_broadcasting')
11 +const test3 = require('./crawling_br_onair_date')
12 +const test4 = require('./crawling_time')
13 +
14 +const {Builder, By, Key, until} = require('selenium-webdriver');
15 +var driver = new webdriver.Builder()
16 +.forBrowser('chrome')
17 +.withCapabilities(webdriver.Capabilities.chrome())
18 +.setChromeOptions(Options)
19 +.build();
20 +samename_list = []
21 +samename_list = test1.first_search(driver,"유재석")
22 +
23 +var driver_1 = new webdriver.Builder()
24 +.forBrowser('chrome')
25 +.withCapabilities(webdriver.Capabilities.chrome())
26 +.setChromeOptions(Options)
27 +.build();
28 +
29 +test2.search_broadcasting(driver_1,"https://people.search.naver.com/search.naver?where=nexearch&sm=tab_ppn&query=%EC%9C%A0%EC%9E%AC%EC%84%9D&os=94702&ie=utf8&key=PeopleService")
30 +
31 +
32 +var driver_2 = new webdriver.Builder()
33 +.forBrowser('chrome')
34 +.withCapabilities(webdriver.Capabilities.chrome())
35 +.setChromeOptions(Options)
36 +.build();
37 +
38 +test3.search_onairanddate(driver_2,"런닝맨")
39 +
40 +
41 +var driver_3 = new webdriver.Builder()
42 +.forBrowser('chrome')
43 +.withCapabilities(webdriver.Capabilities.chrome())
44 +.setChromeOptions(Options)
45 +.build();
46 +
47 +test4.search_broadcasting_time(driver_3,"SBS","일요일","런닝맨")
...\ No newline at end of file ...\ No newline at end of file