how to obtain the text for BeautifulSoup object
Peter Otten
__peter__ at web.de
Tue Mar 20 03:39:58 EDT 2018
Nathan Zhu wrote:
> Hi Team,
>
> could anyone help me?
>
> for webpage having source code like this:
> ...
> <span class="xst thread-name">
> <em>number</em>
> <a class="xst">name</a>
> </span>
>
> I only can use below sentence, since there are a lot of tag em and tag a
> in other area.
> output =
> bs4.BeautifulSoup(res.content,'lxml').findAll("span",{"class":"xst
> thread-name"})
>
> how can I get the text in tag em and tag a under tag span?
for thread in output:
print("em:", thread.em.text)
print("a:", thread.a.text)
print()
More information about the Python-list
mailing list