用BeautifulSoup替换双引号

时间:2017-12-04 13:21:59

标签: python beautifulsoup

我有以下html:

aws s3 sync s3://your-pics .

for i in `find | grep -E "\.jpg$|\.jpg$"`; do gzip  "$i" ; echo $i;  done

aws s3 sync . s3://your-pics --content-encoding gzip --dryrun

我使用BeautifulSoup作为html解析器。

<p>First p</p>
<p></p>
<p>"Second" p</p>
<p> </p>
<p><img class="image" src="image.jpg" /></p>
<p> </p>
<p><img class="image" src="second.jpg" /></p>

如何用单引号替换双引号(仅在img标记中)? 预期的结果是:

from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(html)
imgs = soup.findAll("img")
for img in imgs:
    # replace double quotes with single quotes            
return soup.prettify()

0 个答案:

没有答案