python - How to find tag with particular text with Beautiful Soup? -



python - How to find tag with particular text with Beautiful Soup? -

i have next html (line breaks marked \n):

... <tr> <td class="pos">\n "some text:"\n <br>\n <strong>some value</strong>\n </td> </tr> <tr> <td class="pos">\n "fixed text:"\n <br>\n <strong>text looking for</strong>\n </td> </tr> <tr> <td class="pos">\n "some other text:"\n <br>\n <strong>some other value</strong>\n </td> </tr> ...

how find text looking for? code below returns first found value, need filter fixed text somehow.

result = soup.find('td', {'class' :'pos'}).find('strong').text

upd. if utilize next code:

title = soup.find('td', text = re.compile(ur'fixed text:(.*)', re.dotall), attrs = {'class': 'pos'}) self.response.out.write(str(title.string).decode('utf8'))

then returns fixed text:.

you can pass regular look text parameter of findall, so:

import beautifulsoup import re columns = soup.findall('td', text = re.compile('your regex here'), attrs = {'class' : 'pos'})

python beautifulsoup

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -