Код: Выделить всё
import requests
from bs4 import BeautifulSoup
# string url
str_url = 'https://www.utahrealestate.com/search/map.search'
# get response
response = requests.get(str_url)
# get html
soup = BeautifulSoup(response.text, 'html.parser')
# get the number of listings and assign it to int_n_pages (I cant get this to work; it returns NoneType)
int_n_pages = soup.find('li', {'class': 'view-results'})
# split and get n pages (this does not work because the previous line does not work)
int_n_pages = int(int_n_pages.split(' ')[2])
Что-то вроде...
Код: Выделить всё
# empty list
list_dict_cards = []
# iterate through pages
for int_page in range(1, int_n_pages+1):
# get url
str_url = f'https://www.utahrealestate.com/search/map.search/page/{int_page}/vtype/map'
# get response
response = requests.get(str_url)
# get html
soup = BeautifulSoup(response.text, 'html.parser')
# get property cards
property_cards = soup.find_all(class_='property___card')
# iterate through property cards
for card in property_cards:
# empty dict
dict_card = {}
# get mls number
int_mls = card.find(class_='mls___number').text.split(' ')[1]
# put into dict_card
dict_card['mls'] = int_mls
# I would get other info here as well and put into dict_card
# append dict_card to list_cards
list_dict_cards.append(dict.card)
# make df
df_cards = pd.DataFrame(list_dict_cards)
# save
df_cards.to_csv('./output/df_dict_cards.csv', index=False)
Как/можно это обойти?< /п>
Подробнее здесь: https://stackoverflow.com/questions/707 ... ing-python
Мобильная версия