Background: I am creating websites in Webflow, and then exporting them to be integrated with a PHP backend. Webflow's default file structure is different than our backend, so I'm using Python & BeautifulSoup to help correct some tedious things before actually 'integrating' the exported code.
The first thing I'm trying to solve is changing all image src
s to 'images/xxx' rather than '../images/xxx', which I was able to do like this:
img['src'] = img['src'].replace('../images/', 'images/')
Now I'd like to find all the links and replace their href
s with the structure we use on the backend that looks like this:
<a href="<?=$website_info->url?>/page"></a>
I've been able to find all the links in BS without any issues, and I'm trying to replace their href
s like this:
links = soup.find_all('a', href=True)
for link in links:
link['href'] = '<?=$website_info->url?>/page'
print(link)
but that results in output like this, with every <
and >
replaced with <
and >
, respectively:
<a class="inner-page-nav-link w-nav-link" href="<?=$website_info->url?>/link">Page Name</a>
Does anyone know how I could replace the link href
s without the <
and >
characters being escaped like this?