def postprocess_html(self, soup, first): # Try to find the div containing the first image rudy = soup.find('div', attrs={'id':'rudy_paz'}) # Try to find the div containing the second image rep = soup.find('div', attrs={'id':'rep'}) if rep: # if found, extract the div, clear the body and add the image again. Finished. #rep.extract() while len(soup.body) > 0: soup.body.next.extract() soup.body.insert(0, rudy) soup.body.insert(rudy,rep) return soup