Friday 2 June 2017

How do I access table elements in cheerio?

I have a Table let's say. The elements have no classes, ids or anything except a value. They only have applied style but inside the element. The rest are TD and TR's. Now in Python and BeautifulSoup4 I can do this:

status = soup.select('._lMf')
table =  soup.select('.g  table td')
departure = table[8].getText()
deptime = table[4].getText() + " " + table[5].getText()
terminal = table[6].getText() + " "+ table[11].getText()
arrival = table[19].getText()
arrtime = table[15].getText() + " " + table[16].getText()
arrterminal = table[17].getText() + " " + table[22].getText()
info = table[1].getText()

Select the table and the elements i'm looking for which is a TD and access them. Now I tried almost the same techniques in Cheerio but didn't do it. I got like: TypeError: table[5].text is not a function and Objects.

It successfully logged the easiest 2 that can be directly accessed but it fails on table elements.

This is how i do it in Cheerio:

var table = $('.g  table td')
var deptime = table[5]
var city = table[8].text()
var terminal = table[6].text()   

Help!



via UnknownDeveloper

No comments:

Post a Comment