简体   繁体   中英

Nodejs scraping options

I'm trying to build a scraping engine on node for my currency exchange graphs, at the moment I'm using request+cheerio, but since some bank websites don't use id/class'es in there html my code sometimes looks like:

var eurcur = parsedHTML('p','body')
                               .eq(1).children('table')
                                .children('tr').eq(2)
                                 .children('td')
                                  .children('table')
                                   .children('tr').eq(10)
                                    .children('td').eq(4).text()

Any thing else I could use?

You could use jsdom with a full-featured JQuery. This allows you to use more complex selectors that Cheerio doesn't support, including selectors like :first .

However, some of your .children calls (with should be mergable, eg

.children('td')
 .children('table')

to

.children('td > table')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM