我想从zoopla.co.uk上的房屋列表中提取卧室和浴室的数量。我已经订阅了h3标签的文本。它给了我想要的,但是:
Python
my_url = 'https://www.zoopla.co.uk/for-sale/property/b23/?page_size=100&q=B23&radius=0&results_sort=newest_listings&search_source=refine'
house_listings = page_soup.findAll("div", {"class":"listing-results-right clearfix"})
listings = house_listings[3] # item 4 for prototyping
house_bedrooms = listings.h3.text[1]
print(house_bedrooms)
# 4
house_bathrooms = listings.h3.text[3]
print(house_bathrooms)
# 1
为@bigbounty编辑
style = re.findall('(?<=bed ).*(?= for)', str(listings.h2.a.text))
distance = re.findall('\d+\.?\d*', str(listings.ul.li.text))
if style:
print(f"Type of House - {style}")
if distance:
print(f"Distance from Station - {distance}")
# Output:
# Type of House - ['detached house']
# Distance from Station - ['1.2']
对象的html
<div class="listing-results-right clearfix">
<div class="agent_logo">
<img alt="Marketed by Yopa" class="lazy" data-src="https://st.zoocdn.com/zoopla_static_agent_logo_(654234).png"/>
<noscript><img alt="Marketed by Yopa" src="https://st.zoocdn.com/zoopla_static_agent_logo_(654234).png"/></noscript>
</div>
<a class="listing-results-price text-price" href="/for-sale/details/55889526">
£325,000
</a>
<h3 class="listing-results-attr">
<span class="num-icon num-beds" title="4 bedrooms"><span class="interface"></span>4</span> <span class="num-icon num-baths" title="1 bathroom"><span class="interface"></span>1</span> <span class="num-icon num-reception" title="2 reception rooms"><span class="interface"></span>2</span>
</h3>
<h2 class="listing-results-attr">
<a href="/for-sale/details/55889526" style="text-decoration:underline;">4 bed detached house for sale</a>
<span class="listing-results-just-added">Just added</span>
</h2>
<span><a class="listing-results-address" href="/for-sale/details/55889526">Maxted Road, Erdington, Birmingham B23</a></span>
<div class="listing-results-attr">
</div>
<p>
An immaculately presented family home that will highly impress all viewers. Features include a full length lounge, Separate Dining Room, stylish fitted kitchen, Ground Floor WC, four double bedrooms, stunning bathroom suite, detached Garage, carport, ...
</p>
<div class="nearby_stations_schools clearfix">
<ul>
<li class="clearfix">
<span class="interface nearby_stations_schools_national_rail_station" title="Erdington"></span>
<span class="nearby_stations_schools_name" title="Erdington">Erdington</span>
(1.2 miles)
</li>
<li class="clearfix">
<span class="interface nearby_stations_schools_national_rail_station" title="Chester Road"></span>
<span class="nearby_stations_schools_name" title="Chester Road">Chester Road</span>
(1.3 miles)
</li>
</ul>
<div style="clear:both;">
<small>Note: Distances are straight line measurements</small>
</div>
</div>
</div>
输出:
相关问题 更多 >
编程相关推荐