prumpi

Untitled

Aug 2nd, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. #Андриевский. Парсер карточек.
  2. import requests
  3. from bs4 import BeautifulSoup
  4. import csv
  5.  
  6. HOST = 'https://minfin.com.ua'
  7. URL = 'https://minfin.com.ua/cards/'
  8. #ниже редактируем обе строки, чтобы были пары словаря.
  9. HEADERS = {
  10. 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
  11. 'user-agent': 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36'
  12. }
  13.  
  14. def get_html(url, params=''):
  15.     r = requests.get(url, headers=HEADERS,params=params)
  16.     return r
  17.  
  18. """  
  19. Проверка того, что до сих пор написанное работает
  20. html = get_html(URL)
  21. print(html)
  22. """
  23.  
  24. #~00:24:40
  25. def get_content(html):
  26.     soup = BeautifulSoup(html, 'html.parser')
  27.     items = soup.find_all('div', class_='product-item')
  28.     cards = []  
  29.  
  30.     for item in items:
  31.         cards.append(
  32.             {
  33.                 'title':item.find('div', class_='title').get_text(),
  34.                 'link_product': item.find('div', class_='title').find('a').get('href'),
  35.                 'brand': item.find('div', class_='brand' ).get_text(),
  36.                 'card_img': item.find('div', class_='image').find('img').get('src')
  37.                
  38.                
  39.             }
  40.         )
  41.     return cards
  42.    
  43. html = get_html(URL)
  44. print(get_content(html.text))
  45.  
  46. #00:38:37
Add Comment
Please, Sign In to add comment