Home python How to find all tags to enter the name of the class...

How to find all tags to enter the name of the class using Beautifulsoup Python?

Author

Date

Category

Dana Structure:

& lt; td class = '1234_sfsfs' & gt; & lt; span eu = '333' & gt; & lt; / span & gt ; & lt; / td & gt;
& lt; td class = '1234_fddfd' & gt; & lt; span eu = 'fkdjnv' & gt; & lt; / span & gt; & lt; / td & gt;
& lt; td class = '1234_bjnieujrini' & gt; & lt; span eu = 'kdfjnvk' & gt; & lt; / span & gt; & lt; / td & gt;
& lt; TD Class = '11234_fddfd' & gt; & lt; span eu = 'dkdv' & gt; & lt; / span & gt; & lt; / td & gt;
& lt; td class = 'fddfd' & gt; & lt; span eu = 'vd' & gt; & lt; / span & gt; & lt; / td & gt;

As you can use BeautifulSoup to find all the TD tags, which in the name of the class there are '1234 _' , then inside them find the & lt tag; span & gt; He already gets the name of the attribute EU

Soup.find_all ('TD', Class _ = '?') Find ('Span'). Get ('EU')


Answer 1, Authority 100%

from bs4 import beautifulsoup
Import Re.
html_doc = "" "& lt; td class = '1234_sfsfs' eu = '333' & gt; & lt; / td & gt;
& lt; td class = '1234_fddfd' eu = 'fsvs' & gt; & lt; / td & gt;
& lt; td class = '1234_bjnieujrini' eu = 'BBBBC' & GT; & LT; / TD & GT;
& lt; td class = '11234_fddfd' eu = 'fsvs' & gt; & lt; / td & gt;
& lt; td class = 'fddfd' & gt; & lt; / td & gt; "" "
Soup = beautifulsoup (HTML_DOC, 'HTML.PARSER')
Links = [Item ['EU'] for item in soup.findall ('TD', ATTRS = {'Class': Re.compile ("1234_")})]
For i in Links:
  Print (I)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions