Sep-21-2020, 06:08 PM
Hello team,
I would like to share a script I have created.
It gets the name and price of a product for each url.
It looks like that:
I would like to share a script I have created.
It gets the name and price of a product for each url.
It looks like that:
# USED LIBRARIES import urllib.request from bs4 import BeautifulSoup #URLS FROM WHICH NAME AND PRICE FROM EACH PRODUCT ARE RETRIEVED. ALL PAGES SHOULD HAVE THE SAME FORMAT urls = ['https://gigatron.rs/ssd/wd-ssd-green-series-wds480g2g0a-193671', 'https://gigatron.rs/ssd/wd-ssd-blue-250gb-25-sata-iiiwds250g2b0a-250gb-25-sata-iii-do-550-mbs-125220', 'https://gigatron.rs/ssd/silicon-power-ssd-512gb-25-sata-iii-ace-a55sp512gbss3a55s25-512gb-25-sata-iii-do-560-mbs-144553', 'https://gigatron.rs/ssd/crucial-ssd-bx500-serijact120bx500ssd1-165010'] #LIST WERE THE NAME AND PRICE ARE STORED data = [] #THE MAGIC HAPPENS HERE for i in urls: page = urllib.request.urlopen(i) soup = BeautifulSoup(page, features='lxml') name = soup.find('h1', {'itemprop':'name'}).text price = price = soup.find('span', {'itemprop':'price'}).text p = [name, price] data.append(p) #DISPLAYS RESULTS for j in data: print(j)Any input on how to improve it or simply discuss about is welcome.