Answer the question
In order to leave comments, you need to log in
Did the parser give 2 errors?
Here is the code:
import requests
from bs4 import BeautifulSoup
HOST = "https://irr.ru/cars/passenger/"
URL = "https://irr.ru/cars/passenger/lexus/"
HEADERS = {
'user-agent': 'tyt user-agent',
'accept': 'tyt accept'
}
def get_html(url, params=''):
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_='listing__item')
wgg = []
for item in items:
wgg.append(
{
'title':item.find('div', class_='listing__itemInner').find('div', class_='listing__itemColumn listing__itemColumn_main').find('div', class_='listing__itemTitleWrapper').find('div', class_='listing__itemTitle').find('div', class_='js-productListingProductName').get_text(),
'link':item.find('div', class_='listing__itemInner').find('div', class_='listing__itemColumn listing__itemColumn_main').find('div', class_='listing__itemTitleWrapper').find('a').get('href'),
'foto':item.find('div', class_='listing__itemInner').find('div', class_='listing__itemInner').find('div', class_='listing__itemColumn').find('div', class_='listing__imageWrapper').find('img').get('src'),
'cena':item.find('div', class_='listing__itemInner').find('div', class_='listing__itemColumn listing__itemColumn_price').find('div', class_='listing__itemPrice').get_text(),
}
)
return wgg
html = get_html(URL)
get_content(html.text)
Answer the question
In order to leave comments, you need to log in
And think about the error logically? In Python, everything, all variables, functions are objects. Objects have built-in attributes, for example, a string has string functions. BS creates and uses its own objects at work, and they also have their own functions, for example, this find. But if the previous action (like a function) didn't return anything (for some reason) and the result is an object of type NoneType, can it have the same built-in attributes as a normal BS object? So, we need to figure out why the NoneType object is created, to which the find built-in function is applied on line 25.
If you comment out the title and foto, in which the problem, then everything works:
[{'cena': '\n \t 2\xa0345\xa0000\xa0руб.\n \t ',
'link': 'https://irr.ru/cars/passenger/used/lexus-lx-570-vnedorozhnik-2011-g-v-probeg-117000-km-avtomat-5-7-l-advert740313755.html'},
{'cena': '\n \t 1\xa0200\xa0000\xa0руб.\n \t ',
'link': 'https://irr.ru/cars/passenger/used/lexus-gx-470-vnedorozhnik-2004-g-v-probeg-133569-km-avtomat-4-7-l-advert750625481.html'},
{'cena': '\n \t 1\xa0320\xa0000\xa0руб.\n \t ',
'link': 'https://irr.ru/cars/passenger/used/lexus-rx-270-vnedorozhnik-2011-g-v-probeg-115000-km-avtomat-advert749088541.html'},
{'cena': '\n \t 1\xa0500\xa0000\xa0руб.\n \t ',
'link': 'https://irr.ru/cars/passenger/used/lexus-gs-250-sedan-2013-g-v-probeg-142145-km-avtomat-2-5-l-advert753188137.html'},
{'cena': '\n \t 1\xa0839\xa0999\xa0руб.\n \t ',
'link': 'https://irr.ru/cars/passenger/used/lexus-lx-570-vnedorozhnik-2008-g-v-probeg-265000-km-avtomat-5-7-l-advert752860724.html'},
{'cena': '\n \t 845\xa0000\xa0руб.\n \t ',
'link': 'https://irr.ru/cars/passenger/used/lexus-rx-350-vnedorozhnik-2006-g-v-probeg-196000-km-avtomat-3-5-l-advert752339702.html'},
{'cena': '\n \t 1\xa0400\xa0000\xa0руб.\n \t ',
'link': 'https://irr.ru/cars/passenger/used/lexus-ls-460-sedan-2012-g-v-probeg-390000-km-avtomat-advert744369992.html'},
{'cena': '\n \t 3\xa0900\xa0000\xa0руб.\n \t ',
'link': 'https://irr.ru/cars/passenger/used/lexus-lx-limuzin-2010-g-v-probeg-44000-km-avtomat-advert699227821.html'},
{'cena': '\n \t 3\xa0400\xa0000\xa0руб.\n \t ',
'link': 'https://irr.ru/cars/passenger/used/lexus-lx-570-vnedorozhnik-2013-g-v-probeg-75000-km-avtomat-advert753194033.html'}]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question