python - Beautifulsoup, unable to compare strings -


i'm trying write web spider gather me links , text. have table i'm working , second cell of each row has number in it, want number, if it's 1 need grab links , text in cell 2&4.

everything works fine except can't seem able compare numbers cell list of numbers have.

i number using cells[1].get_text() (i create list of cells each row), works fine , type() returns 'class 'str'', make sure convert numbers list string.

but when try compare them returns 'false'

import bs4  file = open(r"some html file", 'rb') rng_lst = [str(x) x in range(5, 43)]   soup = bs4.beautifulsoup(file)  table = soup.findall('table')[0] row in table.findall('tr'):     cells = row.findall('td')     if len(cells) >= 6:         check = cells[1].get_text()         n in rng_lst:             if n == check:                 # stuff 

i've tried can think of , 'false', using == or 'is' doesn't work, if try using 'in' work if need cell number 5 can 15 or 25 also.

most likely, need strip text getting cell:

check = cells[1].get_text(strip=true) 

it still guess, "educated" one.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -