-1
Good afternoon everyone, I’m with a problem that I haven’t been able to solve or found any related.
If I have:
codigo_pagina = '''<li><span><span style="font-family: Courier New"><a href="page1/somethingA.aspx">
Something1</a></span></span></li>
<li><span><span style="font-family: Courier New"><a href="page1/somethingB.aspx">Something2</a></span></li>
<li><span style="font-family: Courier New"><a href="page1/somethingC.aspx">**Something3**</a></span><span><span style="font-family: Courier New">
(<a href="page1/anotherthing.aspx">anothertext</a>)</li>
soup = BeautifulSoup(codigo_pagina, "lxml")
path = soup.findAll('a', href=True, text="Something3")
print(path)
i get:
>>> [<a href="page1/somethingC.aspx">Something3</a>]
which is what I want.
But if Something3 goes to a new line (as if I gave a "enter" href is no longer found and I get nothing:
codigo_pagina = '''<li><span><span style="font-family: Courier New"><a href="page1/somethingA.aspx">
Something1</a></span></span></li>
<li><span><span style="font-family: Courier New"><a href="page1/somethingB.aspx">Something2</a></span></li>
<li><span style="font-family: Courier New"><a href="page1/somethingC.aspx">
**Something3**</a></span><span><span style="font-family: Courier New">
(<a href="page1/anotherthing.aspx">anothertext</a>)</li>
So I get nothing...
>>>
I tried to eliminate the new Lines ( n) with
soup.replace('\n', ' ').replace('\r', ''), para então fazer o findAll, mas dá-me o erro
Typeerror: 'Nonetype' Object is not callable `` because the Soup variable is not a string. I could do it in the path variable but it is no longer worth anything because it does not "see" that the text of href I want is in the next line.– Bgreat