python - How to find elements by class -
i'm having trouble parsing html elements "class" attribute using beautifulsoup. code looks this
soup = beautifulsoup(sdata) mydivs = soup.findall('div') div in mydivs: if (div["class"]=="stylelistrow"): print div
i error on same line "after" script finishes.
file "./beautifulcoding.py", line 130, in getlanguage if (div["class"]=="stylelistrow"): file "/usr/local/lib/python2.6/dist-packages/beautifulsoup.py", line 599, in __getitem__ return self._getattrmap()[key] keyerror: 'class'
how rid or error?
you can refine search find divs given class using bs3:
mydivs = soup.findall("div", { "class" : "stylelistrow" })
Comments
Post a Comment