2013-10-10 33 views
-1

我在看是這樣的:如何使用node.js在div標籤內部刮擦?

<div class="f00" thing="??" other-thing="???"></div> 

我想獲得?和?我完全陷入困境。我試圖得到所有的div裏面包含的這個HTML,但是在這個層次上有很多其他的代碼,所以我只是得到了我不需要的html牆。任何幫助將不勝感激。

回答

-1

包你正在尋找因爲是htmlparser2。我特別喜歡將它與cheerio一起使用,它是一種圍繞它的包裝並提供類似於jQuery的功能。

你會做這樣的事情:

$ = cheerio.load(yourHtml); 
thing = $('.foo').attr('thing'); 
otherThing = $('.foo').attr('other-thing'); 
0

您可以使用jQuery與node.js,它使得使用DOM更容易。
有了它,你可以做的東西一樣......

var thing = $('.f00').attr('thing'); 
var other-thing = $('.f00').attr('other-thing'); 

看一看jQuery的API,讓您可以做什麼?它可以做很多事情更好的主意。

編輯
您需要安裝jQuery。

npm install jquery 

有關說明如何讓故宮看看here
有關節點jQuery的更多信息,看看在github repository

希望它能幫助:)