[Solved] how to make the width and height x2 using python Regular


Don’t use regular expressions to parse HTML. Use BeautifulSoup

>>> from BeautifulSoup import BeautifulSoup
>>> ht="<html><head><title>foo</title></head><body><p>whatever: <img src="https://stackoverflow.com/questions/5878079/foo/img.png" height="111" width="22" /></p><ul><li><img src="foo/img2.png" height="32" width="44" /></li></ul></body></html>"
>>> soup = BeautifulSoup(ht)
>>> soup
<html><head><title>foo</title></head><body><p>whatever: <img src="https://stackoverflow.com/questions/5878079/foo/img.png" height="111" width="22" /></p><ul><li><img src="foo/img2.png" height="32" width="44" /></li></ul></body></html>
>>> soup.findAll('img')
[<img src="https://stackoverflow.com/questions/5878079/foo/img.png" height="111" width="22" />, <img src="foo/img2.png" height="32" width="44" />]
>>> for img in soup.findAll('img'):
...     ht = int(img['height'])
...     wi = int(img['width'])
...     img['height'] = str(ht * 2)
...     img['width'] = str(wi * 2)
...     
... 
>>> print soup.prettify()
<html>
 <head>
  <title>
   foo
  </title>
 </head>
 <body>
  <p>
   whatever:
   <img src="https://stackoverflow.com/questions/5878079/foo/img.png" height="222" width="44" />
  </p>
  <ul>
   <li>
    <img src="foo/img2.png" height="64" width="88" />
   </li>
  </ul>
 </body>
 </html>
>>> 

2

solved how to make the width and height x2 using python Regular