1
import requests
from bs4 import BeautifulSoup
r = requests.get(url)
soup = BeautifulSoup(r.content, 'lxml')
image = soup.select_one('#productImage > li > a > span > img')
print(image)

<img alt="Image" src="https://cdn.cloudflare.com/image.jpg" title="Image"/>

I would like to print like this:

https://cdn.cloudflare.com/image.jpg

Thank you for your answers guys

HTML:

<span class="imgInner">
<img src="https://cdn.cloudflare.com/image.jpg" alt="image" title="image">
</span>
DanPY
  • 25
  • 4

1 Answers1

0

Try like this. You can follow this post.

soup = BeautifulSoup("""<span class="imgInner">
<img src="https://cdn.cloudflare.com/image.jpg" alt="image" title="image">
</span>""", 'lxml')
image = soup.select_one('span.imgInner img')['src']
print(image)
MendelG
  • 14,885
  • 4
  • 25
  • 52
Samsul Islam
  • 2,581
  • 2
  • 17
  • 23