EXTREMEXPLOIT

PC Componentes Scraping

Jan 8th, 2020
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.76 KB | None | 0 0
  1. from bs4 import BeautifulSoup as BS
  2. import matplotlib.pyplot as plt
  3. import requests
  4. import os
  5. import urllib.request
  6.  
  7. URL = "http://bit.ly/2ZZKKaU"
  8. HEADERS = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"}
  9. HTML_Page = requests.get(URL, headers=HEADERS)
  10. MySoup = BS(HTML_Page.content, "html.parser")
  11.  
  12. def Get_Prices_Plot(Prices_Register):
  13.     plt.plot(Prices_Register)
  14.     plt.xlabel("Time")
  15.     plt.ylabel("Prices")
  16.     plt.show()
  17.  
  18. Product_Information = (MySoup.findAll("div", {"class": "col-xs-12 col-sm-12 col-md-6"}))[1]
  19. Product_Name = (Product_Information.findAll("h1", {"class": "h4"}))[0].get_text()
  20. Product_Price = (Product_Information.findAll("div", {"class": "precioMain h1"}))[0].get_text()
  21. Numeric_Price = float(Product_Price.replace("€", "").replace(",", "."))
  22.  
  23. if os.path.isfile("./Product_Prices.txt"):
  24.     Price_File = open("./Product_Prices.txt", "r")
  25.     FileContent = Price_File.readlines()
  26.     Price_File.close()
  27.  
  28.     Best_Price = float(FileContent[0])
  29.     Prices_Register = list(map(float, FileContent[1].split(",")))
  30.     Prices_Register_List = Prices_Register
  31.     if Best_Price > Numeric_Price:
  32.         Best_Price = Numeric_Price
  33.     Prices_Register.append(Numeric_Price)
  34.     Prices_Register = str(Prices_Register).replace("[", "").replace("]", "")
  35.  
  36.     Price_File = open("./Product_Prices.txt", "w")
  37.     Price_File.write(str(Best_Price) + str("\n"))
  38.     Price_File.write(Prices_Register)
  39.     Price_File.close()
  40.     Get_Prices_Plot(Prices_Register_List)
  41.  
  42. else:
  43.     Price_File = open("./Product_Prices.txt", "w")
  44.     Price_File.write(str(Numeric_Price) + str("\n"))
  45.     Price_File.write(str(Numeric_Price))
  46.     Price_File.close()
  47.     Prices_Register_List = [Numeric_Price]
  48.     Get_Prices_Plot(Prices_Register_List)
Add Comment
Please, Sign In to add comment