Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Андриевский. Парсер карточек.
- import requests
- from bs4 import BeautifulSoup
- import csv
- HOST = 'https://minfin.com.ua'
- URL = 'https://minfin.com.ua/cards/'
- #ниже редактируем обе строки, чтобы были пары словаря.
- HEADERS = {
- 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
- 'user-agent': 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36'
- }
- def get_html(url, params=''):
- r = requests.get(url, headers=HEADERS,params=params)
- return r
- """
- Проверка того, что до сих пор написанное работает
- html = get_html(URL)
- print(html)
- """
- #~00:24:40
- def get_content(html):
- soup = BeautifulSoup(html, 'html.parser')
- items = soup.find_all('div', class_='product-item')
- cards = []
- for item in items:
- cards.append(
- {
- 'title':item.find('div', class_='title').get_text(),
- 'link_product': item.find('div', class_='title').find('a').get('href'),
- 'brand': item.find('div', class_='brand' ).get_text(),
- 'card_img': item.find('div', class_='image').find('img').get('src')
- }
- )
- return cards
- html = get_html(URL)
- print(get_content(html.text))
- #00:38:37
Add Comment
Please, Sign In to add comment