crawling_broadcasting.js 2.98 KB
var async = require('async');
var webdriver = require('selenium-webdriver');
var options = {desiredCapabilities: {browserName: 'chrome'}};
const {Builder, By, Key, until} = require('selenium-webdriver');
const screen = {
    width: 640,
    height: 480
};
var a=0
var breaktheloop = false
module.exports = {
    search_broadcasting : function(driver,url) {
        driver
            .get(url)
            .then(() => {
                driver.findElement(webdriver.By.id('pagination_76'))
                .then ( paginationBtn => {
                    paginationBtn.findElements(webdriver.By.className('bt_next'))
                    .then(Btn_next => {
                        driver.findElement(webdriver.By.id('listUI_76'))
                        .then(contentsUI => {
                            contentsUI.findElements(webdriver.By.tagName('li'))
                            .then(elems => {
                                elems.forEach(elem => {
                                    elem.getText()
                                    .then(text => {
                                        console.log(text)
                                    })
                                })
                            })
                            clickandget()
                            function clickandget() {
                                Btn_next[0].isDisplayed().then(function(state) {
                                    if(state) {
                                        Btn_next[0].click()
                                        sleep(500).then(()=> {
                                            contentsUI.findElements(webdriver.By.tagName('li'))
                                            .then(elems => {
                                                elems.forEach(elem => {
                                                    elem.getText()
                                                    .then(text => {
                                                        console.log(text)
                                                    })
                                                })
                                            })
                                        })
                                    }
                                    else {
                                        console.log(state)
                                    }
                                })
                            }
                        })
                    })
                })
            })

        function getContentsandClickNext(callback) {
            driver.findElement(webdriver.By.id('listUI_76'))
            .then(contentsUI => {
                contentsUI.findElements(webdriver.By.tagName('li'))
                .then(elems => {
                    elems.forEach(elem => {
                        elem.getTex
                    })
                })
            })
        }

        function sleep (time) {
            return new Promise((resolve) => setTimeout(resolve, time));
        }
    }
}