Get image width from HTML code
<p>I can get the <code>width</code> attribute of an image using <code>BeautifulSoup</code> as follows:</p>

<pre><code>img = soup.find("img")
width = img["width"]
</code></pre>

<p>The problem is that <code>width</code> can be set in <code>CSS</code> file or not set at all.</p>

<p>I would like to extract the value without downloading the image from <code>img["src"]</code> How can I do it in Python to extract the value if it's set somewhere (HTML or CSS) or get the default value the browser will render (if not set)?</p>

<p>The quick answer is: you can't - the resultant size of an image is based on evaluation of CSS, and indeed JS. You'd need to do all that work in order to find your answer.</p>

<p>Another approach might be to use a real browser to do that work for you, and then ask it what the width is. See <a href="http://phantomjs.org/" rel="nofollow">PhantomJS</a>, and <a href="http://www.seleniumhq.org/" rel="nofollow">Selenium</a>.</p>

python selenium web-scraping beautifulsoup phantomjs