Python Forum
Getting a URL from Amazon using requests-html, or beautifulsoup - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Getting a URL from Amazon using requests-html, or beautifulsoup (/thread-38622.html)



Getting a URL from Amazon using requests-html, or beautifulsoup - aaander - Nov-06-2022

I'm new to scraping and am working on a scraper, I'm trying to figure out how to pull a URL from the src of this line of HTML:

<img alt="Bube Dame König Gras [Import allemand]" src="https://m.media-amazon.com/images/I/81f+DecFsrL._SY445_.jpg" data-old-hires="https://m.media-amazon.com/images/I/81f+DecFsrL._SL1500_.jpg" onload="markFeatureRenderForImageBlock(); this.onload='';setCSMReq('af');if(typeof addlongPoleTag === 'function'){ addlongPoleTag('af','desktop-image-atf-marker');};setCSMReq('cf')" class="a-dynamic-image a-stretch-vertical" id="landingImage" data-a-dynamic-image="{&quot;https://m.media-amazon.com/images/I/81f+DecFsrL._SY679_.jpg&quot;:[679,480],&quot;https://m.media-amazon.com/images/I/81f+DecFsrL._SY550_.jpg&quot;:[550,389],&quot;https://m.media-amazon.com/images/I/81f+DecFsrL._SY445_.jpg&quot;:[445,315],&quot;https://m.media-amazon.com/images/I/81f+DecFsrL._SY500_.jpg&quot;:[500,353],&quot;https://m.media-amazon.com/images/I/81f+DecFsrL._SY606_.jpg&quot;:[606,428]}" style="max-width: 160.471px; max-height: 227px;"> </div>

I haven't had any luck pointing to this line to get the src. I'd settle for copying the html, making it text and finding it that way, it might actually be better that way. I'm using request-html, though Beautifulsoup might do this better. Any help would be appreciated!


RE: Getting a URL from Amazon using requests-html, or beautifulsoup - snippsat - Nov-06-2022

Like this.
>>> img = soup.find('img')
>>> img.get('src')
'https://m.media-amazon.com/images/I/81f+DecFsrL._SY445_.jpg'