我的正则表达式正在生成拆分结果,因此我必须为快速修复下标
代码
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 3 for prototyping
house_type = re.findall('(?:(?!.for).)*', str(listings.h2.a.text))
print(house_type)
# `['4 bed detached house', '', 'for sale', '']`
修理
house_type = re.findall('(?:(?!.for).)*', str(listings.h2.a.text))[0]
print(house_type)
# 4 bed detached house
但除此之外,我需要一个新的正则表达式来更好地匹配
所需匹配项
从“bed”后面的单词开始(减去下面的空格),忽略“待售”部分。
e、 结果:detached house
,terrace house
,semi-detached house
,flat
,maisonette
这应该是您所需要的全部:
Demo
相关问题 更多 >
编程相关推荐