1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
def load_product(url): #il récupére les elements d'un produit dune page
page = requests.get(url)
BS = BeautifulSoup(page.content, 'html.parser')
getOverview = BS.find('section', id='over').find('table', id='viewer')
K = getOverview.find('tbody').find_all('tr')[1:]
sas = []
contImage = BS.find('section', class_='section-img').find("img")
for e in K:
Val = e.find('td', class_='table-value').text
sas.append(Val.strip())
sas.append(contImage.get("src"))
download_image(contImage.get("src"),"Image_An")
return sas
def download_image(url, pathname):
if not os.path.isdir(pathname):
os.makedirs(pathname)
data = "/wp-content/uploads/"
if data in url:
response = requests.get(url, stream=True)
file_size = int(response.headers.get("Content-Length", 0))
filename = os.path.join(pathname, url.split("/")[-1])
progresse = tqdm(response.iter_content(1024), f"Downloading {filename}", total=file_size, unit="B", unit_scale=True, unit_divisor=1024)
with open(filename, "wb") as file:
for data in progresse:
file.write(data)
progresse.update(len(data)) |
Partager