Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use css selectors to parse an html string in node? [closed]

I'm writing a scraper in node. Is there a module out there that will allow me to work with css selectors?

like image 766
George Mauer Avatar asked Jan 12 '13 04:01

George Mauer


People also ask

Can we use text () in CSS selector?

For locating elements by using their text contents, CSS selectors and XPath provide methods to find text within the elements. If an element contains specific text, this will return the element back to the test.

How do you parse HTML?

If you just want to parse HTML and your HTML is intended for the body of your document, you could do the following : (1) var div=document. createElement("DIV"); (2) div. innerHTML = markup; (3) result = div. childNodes; --- This gives you a collection of childnodes and should work not just in IE8 but even in IE6-7.


1 Answers

Look at the excellent jsdom, and specifically this section, where it shows how you can leverage jQuery in Node to scrape HTML documents, thus using the CSS-like selectors that jQuery offers.

like image 172
matehat Avatar answered Oct 13 '22 11:10

matehat