0

I tried to fetch some pictures from a website using Python but it is not easy to me.

Here is what I did below:

import requests
from bs4 import BeautifulSoup
import re

url = "https://www.mayde.com/ponytail"
res = requests.get(url)
res.raise_for_status()
soup = BeautifulSoup(res.text, "lxml")
item_address1 = soup.find_all("div",attrs={"class":"BEmRci heightByImageRatio heightByImageRatio4"})
print(item_address1[0]["style"])

The result is:

background-image:url(https://static.wixstatic.com/media/42be90_61424ae0ff87475a8c536ba3afe1410d~mv2.jpg/v1/fill/w_64,h_100,al_c,q_80,usm_0.66_1.00_0.01/42be90_61424ae0ff87475a8c536ba3afe1410d~mv2.jpg);background-size:contain

I want:

https://static.wixstatic.com/media/42be90_61424ae0ff87475a8c536ba3afe1410d~mv2.jpg/v1/fill/w_64,h_100,al_c,q_80,usm_0.66_1.00_0.01/42be90_61424ae0ff87475a8c536ba3afe1410d~mv2.jpg
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
Peter Yun
  • 9
  • 2
  • This is simple Python string processing. Find the open parentheses, find the closed parentheses, grab the text in between. – Tim Roberts Jul 27 '22 at 22:05

1 Answers1

0

Just basic string processing.

i = item_address1.find('(')
j = item_address1.find(')')
item_address1 = item_address1[i+1:j]
Tim Roberts
  • 48,973
  • 4
  • 21
  • 30