3
I have the following html:
<p>Um acidente no cruzamento da rua ... </p>
<div id="marca"></div>
<p>Um acidente no cruzamento ......</p>
<div id="marca2"></div>
I’m trying to do it like this:
def text_view(self):
soup = BeautifulSoup(self.text)
try:
marca1 = BeautifulSoup(self.get_images())
soup.find("div", {"id": "marca"}).replaceWith(marca1)
except:
pass
try:
marca2 = BeautifulSoup(self.get_images())
soup.find("div", {"id": "marca2"}).replaceWith(marca2)
except:
pass
return soup
But it only replaces the text of the first div. What can it be?
What is
self.get_images
? What does it return? And the second code (findAll
) is still so, withid
? Note that in your code thediv
owns the classmarca2
, not the id. Or it was just a mistake when asking the question?– mgibsonbr
this self.get_images() returns an html list of images. I corrected the code. After other attempts I haven’t been able to yet ):
– csassis
ok, and this list of images has ids? I noticed that you are using the same values (the return of
self.get_images()
) in two different places. If there are repeated ids, it can be a problem - although I’m not sure if it already occurs in Beautifulsoup itself or only later when rendering HTML.– mgibsonbr