Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import requests
- from bs4 import BeautifulSoup
- URL = 'https://auto.ria.com/newauto/marka-jeep/'
- HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0', '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('div', class_='proposition')
- #for item in items: print(item)
- cars = []
- for item in items:
- usd_price, uah_price = map(str.strip, item.find('div', class_='proposition_price').get_text().split('•'))
- #print(usd_price)
- cars.append({
- 'title': item.find('div', class_='proposition_title').find('strong').get_text(strip=True),
- 'link': HOST + item.find('div', class_='proposition_title').find('a').get('href'),
- 'usd_price': usd_price,
- 'uah_price' : uah_price,
- 'city': item.find('div', class_=re.compile('^proposition_region')).find('strong').get_text(),
- })
- return cars
- def parse():
- html = get_html(URL)
- if html.status_code == 200:
- #print(html.text)
- cars = get_content(html.text)
- for car in cars: print(car)
- else:
- print('Error')
- parse()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement