Showing
5 changed files
with
166 additions
and
120 deletions
... | @@ -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 | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -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 | ... | ... |
main.js
0 → 100644
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 |
-
Please register or login to post a comment