I have a html file say:
<html>...
<li id="123"></li>
<li id="3455"></li>
....
</html>
how do I get the value for all the ids alone in python using BeautifulSoup ?
the desired output is : ["123","3455"]
To get the list you want, use a list comprehension. It can be done in one line as follows (last line):
html = '<html> <li id="123"></li><li id="3455"></li> </html>'
soup = BeautifulSoup(html)
attrs = [li['id'] for li in soup.find_all('li')]