Carica file su ''

master
MickSlash 2021-05-05 09:21:07 +00:00
parent 13ef617318
commit 7447c0e414
1 changed files with 39 additions and 0 deletions

39
amazon_webscraping.py Normal file
View File

@ -0,0 +1,39 @@
import bs4, requests
class ProdottoAmazon():
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36',
}
def __init__(self,url_prodotto):
self.url_prodotto = url_prodotto
def establishConnect(self):
res = requests.get(self.url_prodotto,headers=self.headers)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text,"html.parser")
return soup
def getAmazonTitle(self):
soup = self.establishConnect()
elems = soup.select('#productTitle')
return elems[0].text.strip()
def getAmazonPrice(self):
soup = self.establishConnect()
elems = soup.select('#price_inside_buybox')
return elems[0].text.strip()
def getAll(self):
prodotto = self.getAmazonTitle()
prezzo = self.getAmazonPrice()
print(f"Il Prezzo del Prodotto {prodotto} é di {prezzo}")
productURL = input("Inserisci l'url di Amazon --> ")
prodotto = ProdottoAmazon(productURL)
prodotto.getAll()