import mysql.connector #allows connection to database. #pip install mysql-connector-python
#DB Config
config = {
'user':'yuri',
'password':'STyecJowufkuph9',
'host':'192.168.178.55',
'database':'mindfactory_scraper'
}
mydb = mysql.connector.connect(**config)
for link in (links):
getHTML = requests.get(link)
getHTMLr = getHTML.content # This will give you raw HTML from getLink1TB
soupify = BeautifulSoup(getHTMLr, 'html.parser')
# containers = soupify.find("div",{"class":"pcontent"})
# print(containers)
title_container = soupify.find("div", {"class":"visible-xs visible-sm"})
title = title_container.text.strip()
#price
price_container = soupify.find("div", {"class":"pprice"})
price = price_container.text.replace(",",".")
price_strip = re.sub('[^0-9.]', '', price)
#price per TB
priceTB = float(price_strip)/int(size)
#link
href_container = soupify.find('a',{'class':'phover-complete-link'})['href']
href = href_container
store = "Mindfactory"
print(title)
print(size + "TB")
print(price_strip + " EUR")
print(currentDate)
print(priceTB)
print(href)
# mycursor = mydb.cursor()
# sql = "INSERT INTO hdd (name, size, price, date, priceTB, href, store) VALUES (%s, %s, %s, %s, %s, %s, %s)"
# val = (title, size, price_strip, currentDate, priceTB, href, store)
# mycursor.execute(sql,val)
# mydb.commit()
# print(mycursor.rowcount, "Hard drives added!")
# else:
# print "Size not added: " + size + " TB"
# Add data to DB
Comments