2016-10-06 13 views
0

我想獲取不同網站的標題。喜歡這個。如何顯示node.js中的網站標題

localhost:1234/index/?url=google.com&url=www.yahoo.com/&url=twitter.com 

如果我到了這個網址,它會在網址的所有提及網站上爬行,並顯示網站的標題。

- Google  
- Yahoo 
- Twitter 

回答

0
var Urls = 'localhost:1234/index/?url=google.com&url=www.yahoo.com/&url=twitter.com'; 
    // remove all special characters like '/' '&' and '=' 
    Urls = Urls.replace(/\&/g, '').replace(/\//g, '').replace(/\=/g, ''); 
    // split it based on url 
    Urls = Urls.split('url'); 
    //delete first element as its not required 
    delete Urls[0] 
    Urls.forEach(function (url) {  
    //split each element based on '.' 
     url = url.split('.'); 
     url.forEach(function (ele) { 
      // if its not 'www' and 'com' 
      if (ele !== 'www' && ele !== 'com') { 
       // the title of url 
       console.log(ele); 
      } 
     }) 
    }) 

,你需要刪除所有特殊字符如上面使用正則表達式,如果網址中含有「.ORG」或「在」 ..等等,那麼還需要包括內部的,如果條件

+0

這不是正確的答案。我說它應該指定網址才能從該網站獲得標題。 –

+0

我認爲這些可以幫助你[link1](https://github.com/ciaranj/node-oauth),[link2](https://rapiddg.com/blog/calling-rest-api-nodejs-script) 。 – kgangadhar