Answer the question
In order to leave comments, you need to log in
Is it possible to extract information from blocks united by one class when parsing a site?
Hello! I want to write a Cian site parser ( https://cian.ru/ ), I write in Python, I use BeautifulSoup.
I ran into such a problem that under one class, in several blocks, there is the information I need (I attach a screen if I formulated the problem incorrectly)
Using the selector for this class:
address_block = item.select_one('div._93444fe79c--labels--1J6M3')
<div class="_93444fe79c--labels--1J6M3">
<a class="_93444fe79c--link--10mjQ" data-name="GeoLabel" href="https://saransk.cian.ru/kupit-kvartiru-mordoviya/" target="_blank">Республика Мордовия</a>,
<a class="_93444fe79c--link--10mjQ" data-name="GeoLabel" href="https://saransk.cian.ru/kupit-kvartiru/" target="_blank">Саранск</a>,
<a class="_93444fe79c--link--10mjQ" data-name="GeoLabel" href="https://saransk.cian.ru/kupit-kvartiru-mordoviya-saransk-oktyabrskiy-044297/" target="_blank">р-н Октябрьский</a>,
<a class="_93444fe79c--link--10mjQ" data-name="GeoLabel" href="https://saransk.cian.ru/kupit-kvartiru-mordoviya-saransk-volgogradskaya-ulica-0231169/" target="_blank">Волгоградская улица</a>,
<a class="_93444fe79c--link--10mjQ" data-name="GeoLabel" href="/cat.php?deal_type=sale&engine_version=2&house%5B0%5D=2192661&offer_type=flat" target="_blank">124</a></div>
Answer the question
In order to leave comments, you need to log in
The solution was provided by Evgeny Palych a little higher in the comments to the post
address_block = item.select_one('div._93444fe79c--labels--1J6M3')
print(address_block.get_text(" "))
# для всех div на странице с классом _93444fe79c--labels--1J6M3
address_blocks = item.select('div._93444fe79c--labels--1J6M3')
for e in address_blocks:
print(e.get_text(" "))
Check out the BeautifulSoup documentation for many examples.
I don’t know about python and this library, but I’ll try to guess:
address_block = item.select_one('div._93444fe79c--labels--1J6M3 a')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question