Advertisement
Typhoon

Get Alza Item data

Aug 26th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. # Install BS4 with pip3 : sudo pip3 install -U beautifulsoup4
  5. from bs4 import BeautifulSoup
  6. # Install Requests with pip3 : sudo pip3 install -U requests
  7. import urllib.request as urllib2
  8.  
  9. # Define URL for data scraping
  10. check_url = "https://www.alza.sk/macbook-pro-13-retina-cz-2015-d2412494.htm"
  11. # Open URL in URLlib
  12. check_page = urllib2.urlopen(check_url)
  13. # Read and parse html data
  14. check_soup = BeautifulSoup(check_page.read(), "html.parser")
  15.  
  16. # Get values with BS
  17. tovar_nazov = check_soup.find_all('h1')[0].text.replace("\n", "").replace("\r", "")
  18. tovar_popis = check_soup.find('div', class_='nameextc').text.replace("\n", "")
  19. tovar_cena = check_soup.find('span', class_='price_withVat').text.replace("\xa0", "")
  20.  
  21. # Print values
  22. print("URL:", check_url)
  23. print("Názov:", tovar_nazov)
  24. print("Popis:", tovar_popis)
  25. print("Cena:", tovar_cena)
  26.  
  27.  
  28. # print("\n##### DEBUG ####")
  29. # print(str(check_soup.find_all('h1')[0].text).encode('utf-8'))
  30. # file_out = open("text.html", "w")
  31. # file_out.write(str(tovar_cena.encode("utf-8")))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement