Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- #pip install requests
- #pip install beautifulsoup4
- URL= 'https://auto.ria.com/newauto/marka-hyundai/'
- HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
- 'Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363', 'accept': '*/*'}
- HOST = 'https://auto.ria.com'
- def get_html(url, params=None):
- r = requests.get(url, headers=HEADERS, params=params)
- return r
- def get_content(html):
- soup = BeautifulSoup(html, 'html.parser')
- items = soup.find_all('a', class_='na-card-item')
- cars =[]
- for item in items:
- uah_price = item.find('span', class_='size15')
- if uah_price:
- uah_price = uah_price.get_text().replace('•', '')
- else:
- uah_price = 'Цены нет'
- cars.append({
- 'title': item.find('div', class_='na-card-name').get_text(strip=True),
- 'link': HOST + item.find('span', class_='link').get('href'),
- 'uah_price': uah_price,
- 'link': item.find('svg', class_='svg_i16_pin').find_next('span').get_text(),
- # class ="na-card-price"
- })
- return cars
- def parse():
- html = get_html(URL)
- if html.status_code == 200:
- cars = get_content(html.text)
- else:
- print("Error")
- parse()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement