最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What does EADDRINUSE error mean? - Stack Overflow

programmeradmin5浏览0评论

I wrote a quick and dirty facebook scraper using selenium webdriver and it worked well for a while but I would occasionally get an EADDRINUSE error. Now I get it all the time and the script barely runs. Here is the error:

        throw error;
        ^

Error: EADDRINUSE connect EADDRINUSE 127.0.0.1:56642
    at ClientRequest.<anonymous> (C:\Users\ConquerJS\node_modules\selenium-webdriver\http\index.js:238:15)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at Socket.socketErrorListener (_http_client.js:308:9)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at emitErrorNT (net.js:1272:8)
    at _binedTickCallback (internal/process/next_tick.js:74:11)

And here is my code. It might make you want to vomit but I was asked to do this and did it reluctantly as fast as I could, and I'm a beginner at coding :

    var webdriver = require('selenium-webdriver'),
    chrome = require('selenium-webdriver/chrome'),
    By = webdriver.By,
    until = webdriver.until;


    var o = new chrome.Options();
    o.addArguments("--disable-notifications");
    var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).setChromeOptions(o).build()
    driver.manage().window().maximize();

    var find = function (el) {
        driver.wait(until.elementLocated(By.css(el)), 10000, 'Could not locate element');
        driver.sleep(700);
        return driver.findElement(By.css(el));
    };

    var findAll = function (el) {
        driver.wait(until.elementLocated(By.css(el)), 10000, 'Could not locate element');
        driver.sleep(700);
        return driver.findElements(By.css(el));
    };

 var styleSheet = `
                    <style>
                        body{
                            font-family: "raleway";
                            font-weight: 100;
                        }

                        h1{
                            margin-top: 60px;
                            font-weight: bold;
                        } 

                        .num{
                            color:red;
                        }

                        .gender{
                            color: orange;
                        }
                        li{
                            display: inline-block;
                            max-width: 100px;
                            max-height: 120px;
                            overflow: hidden;                        
                        }
                        header {
                            width: 100%;
                            background: #3d3da7;
                        }
                        .headerwrap {
                            height: 100px;
                            color: white;
                            line-height: 100px;
                            max-width: 80%;
                            margin: 0 auto;
                        }
                    </style>
                    <header><div class="headerwrap">FBPromoter9000</div></header>
                     `


listAllElements = function (el, loc){
    driver.wait(until.elementLocated(By.css(el)), 10000, 'Could not locate element');
    var findElements = driver.findElements(By.css(el));
        findElements.then(function (options) {
            var htmlFormatting = `
                    <h1>  - There are a total of <span class="num">` + options.length +  ` girls </span> from <span class="num">` + loc + `</span> Currently listed as living in New York</h1>

                `
            console.log(htmlFormatting);
            options.map(function (elem) {
                var picSrc = elem.getAttribute("src");
                    picSrc.then(function(url){
                        var picIndex = options.indexOf(elem);
                        driver.findElements(By.css('._5d-5')).then(function(peopleNames){
                            peopleNames.map(function(personName){
                                if(peopleNames.indexOf(personName) === picIndex){
                                    personName.getText().then(function(t){
                                        driver.findElements(By.css('._2ial')).then(function(profileLinks){
                                            profileLinks.map(function(currentProfile){
                                                if(profileLinks.indexOf(currentProfile) === picIndex){
                                                    currentProfile.getAttribute("href").then(function(linkToProfile){
                                                        console.log("  <li><a href="+"'"+linkToProfile+"'"+">"+"<img src="+"'"+url+"'" + "/></a><br/>" + "<a href="+"'"+linkToProfile+"'"+">"+t+"</a></li>");
                                                    });
                                                };
                                            });
                                        });
                                    });
                                };
                            });
                        });
                    });
            });
        });
};

var scrollToBottom = function () {
    var el = "#browse_end_of_results_footer";
    driver.findElement(By.css(el)).catch(function(err){
        if (err){
            driver.executeScript("window.scrollBy(0, 1000)", "");
            scrollToBottom();
        }else{
            console.log("WASSSSSUUUPP");
        }
    });
}

    driver.get(searchqueryurl);
    find('#email').sendKeys(useremail);
    find('#pass').sendKeys(userpass);
    find('#loginbutton').click();

    var searchForPeople = function(loc){
        driver.get(searchquery);
        scrollToBottom();
        driver.sleep(1000);
        find("#browse_end_of_results_footer").getText().then(function(txt){
            listAllElements('._3u1 ._2ial img', loc);
        });
    };
    console.log(styleSheet);
    searchForPeople('germany');
    searchForPeople('france');
    searchForPeople('Sweden');
    searchForPeople('Norway');
    searchForPeople('Denmark');
    searchForPeople('finland');
    searchForPeople('uk');
    searchForPeople('australia');
    searchForPeople('ireland');
    searchForPeople('switzerland');
    searchForPeople('canada');
    searchForPeople('holland');
    searchForPeople('italy');
    // searchForPeople('austria');
    searchForPeople('belgium');
    searchForPeople('mexico');
    searchForPeople('spain');
    searchForPeople('portugal');
    searchForPeople('greece');
    searchForPeople('poland');
    searchForPeople('ukraine');
    searchForPeople('russia');
    searchForPeople('brazil');
    searchForPeople('colombia');
    searchForPeople('turkey');

The reason I'm console logging html is for the output to e out as a formatted webpage by running the following in the terminal:

node testscript.js > searchresults.html

I wrote a quick and dirty facebook scraper using selenium webdriver and it worked well for a while but I would occasionally get an EADDRINUSE error. Now I get it all the time and the script barely runs. Here is the error:

        throw error;
        ^

Error: EADDRINUSE connect EADDRINUSE 127.0.0.1:56642
    at ClientRequest.<anonymous> (C:\Users\ConquerJS\node_modules\selenium-webdriver\http\index.js:238:15)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at Socket.socketErrorListener (_http_client.js:308:9)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at emitErrorNT (net.js:1272:8)
    at _binedTickCallback (internal/process/next_tick.js:74:11)

And here is my code. It might make you want to vomit but I was asked to do this and did it reluctantly as fast as I could, and I'm a beginner at coding :

    var webdriver = require('selenium-webdriver'),
    chrome = require('selenium-webdriver/chrome'),
    By = webdriver.By,
    until = webdriver.until;


    var o = new chrome.Options();
    o.addArguments("--disable-notifications");
    var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).setChromeOptions(o).build()
    driver.manage().window().maximize();

    var find = function (el) {
        driver.wait(until.elementLocated(By.css(el)), 10000, 'Could not locate element');
        driver.sleep(700);
        return driver.findElement(By.css(el));
    };

    var findAll = function (el) {
        driver.wait(until.elementLocated(By.css(el)), 10000, 'Could not locate element');
        driver.sleep(700);
        return driver.findElements(By.css(el));
    };

 var styleSheet = `
                    <style>
                        body{
                            font-family: "raleway";
                            font-weight: 100;
                        }

                        h1{
                            margin-top: 60px;
                            font-weight: bold;
                        } 

                        .num{
                            color:red;
                        }

                        .gender{
                            color: orange;
                        }
                        li{
                            display: inline-block;
                            max-width: 100px;
                            max-height: 120px;
                            overflow: hidden;                        
                        }
                        header {
                            width: 100%;
                            background: #3d3da7;
                        }
                        .headerwrap {
                            height: 100px;
                            color: white;
                            line-height: 100px;
                            max-width: 80%;
                            margin: 0 auto;
                        }
                    </style>
                    <header><div class="headerwrap">FBPromoter9000</div></header>
                     `


listAllElements = function (el, loc){
    driver.wait(until.elementLocated(By.css(el)), 10000, 'Could not locate element');
    var findElements = driver.findElements(By.css(el));
        findElements.then(function (options) {
            var htmlFormatting = `
                    <h1>  - There are a total of <span class="num">` + options.length +  ` girls </span> from <span class="num">` + loc + `</span> Currently listed as living in New York</h1>

                `
            console.log(htmlFormatting);
            options.map(function (elem) {
                var picSrc = elem.getAttribute("src");
                    picSrc.then(function(url){
                        var picIndex = options.indexOf(elem);
                        driver.findElements(By.css('._5d-5')).then(function(peopleNames){
                            peopleNames.map(function(personName){
                                if(peopleNames.indexOf(personName) === picIndex){
                                    personName.getText().then(function(t){
                                        driver.findElements(By.css('._2ial')).then(function(profileLinks){
                                            profileLinks.map(function(currentProfile){
                                                if(profileLinks.indexOf(currentProfile) === picIndex){
                                                    currentProfile.getAttribute("href").then(function(linkToProfile){
                                                        console.log("  <li><a href="+"'"+linkToProfile+"'"+">"+"<img src="+"'"+url+"'" + "/></a><br/>" + "<a href="+"'"+linkToProfile+"'"+">"+t+"</a></li>");
                                                    });
                                                };
                                            });
                                        });
                                    });
                                };
                            });
                        });
                    });
            });
        });
};

var scrollToBottom = function () {
    var el = "#browse_end_of_results_footer";
    driver.findElement(By.css(el)).catch(function(err){
        if (err){
            driver.executeScript("window.scrollBy(0, 1000)", "");
            scrollToBottom();
        }else{
            console.log("WASSSSSUUUPP");
        }
    });
}

    driver.get(searchqueryurl);
    find('#email').sendKeys(useremail);
    find('#pass').sendKeys(userpass);
    find('#loginbutton').click();

    var searchForPeople = function(loc){
        driver.get(searchquery);
        scrollToBottom();
        driver.sleep(1000);
        find("#browse_end_of_results_footer").getText().then(function(txt){
            listAllElements('._3u1 ._2ial img', loc);
        });
    };
    console.log(styleSheet);
    searchForPeople('germany');
    searchForPeople('france');
    searchForPeople('Sweden');
    searchForPeople('Norway');
    searchForPeople('Denmark');
    searchForPeople('finland');
    searchForPeople('uk');
    searchForPeople('australia');
    searchForPeople('ireland');
    searchForPeople('switzerland');
    searchForPeople('canada');
    searchForPeople('holland');
    searchForPeople('italy');
    // searchForPeople('austria');
    searchForPeople('belgium');
    searchForPeople('mexico');
    searchForPeople('spain');
    searchForPeople('portugal');
    searchForPeople('greece');
    searchForPeople('poland');
    searchForPeople('ukraine');
    searchForPeople('russia');
    searchForPeople('brazil');
    searchForPeople('colombia');
    searchForPeople('turkey');

The reason I'm console logging html is for the output to e out as a formatted webpage by running the following in the terminal:

node testscript.js > searchresults.html
Share Improve this question edited Jan 16, 2017 at 1:37 codemon asked Jan 16, 2017 at 1:34 codemoncodemon 1,6041 gold badge19 silver badges28 bronze badges 9
  • 2 What did you find when you searched that term? – user1106925 Commented Jan 16, 2017 at 1:36
  • 4 EADDRINUSE = E ADDR IN USE (port number in use) – Andrew Li Commented Jan 16, 2017 at 1:37
  • read this question stackoverflow./questions/4075287/… – parik Commented Jan 16, 2017 at 1:38
  • 1 Rup: @jfriend00 has answered nearly 9,000 questions here. You've answered 2. What was that you were saying about making contributions? If you think you're entitled to someone's assistance, you're mistaken. – user1106925 Commented Jan 16, 2017 at 2:15
  • 1 So if you found things in your research you should reference them in the question with an explanation of why they didn't work instead of blindly asking what that error means. Surely you found out what it at least means and can ask a more intelligent question based on this supposed research. Some reading in the help center will also be beneficial research for the future – charlietfl Commented Jan 16, 2017 at 2:36
 |  Show 4 more ments

2 Answers 2

Reset to default 3

The accepted answer by Nicholas Smith may not be correct. Selenium polls ChromeDriver which can exhaust the ephemeral ports in Windows. See this GitHub issue: https://github./seleniumhq/selenium/issues/2888

The error EADDRINUSE means you have multiple instances of your server running or multiple node.js servers running on your desired port.

发布评论

评论列表(0)

  1. 暂无评论