【发布时间】:2019-06-15 12:56:51
【问题描述】:
我用了漂亮的汤,并提取了一些 html,结果是:
print(e)
<p class="top-half listing-results-marketed">
<small>
Listed on
18th Jan 2017
by
</small><br/>
<span>xxx Agents</span>
我只想提取日期和地产代理。
为了提取代理,我使用了:
print(e.span.text)
xxx Agents
为了提取数据,我使用:
print(e.small.text.strip())
最终得到:
Listed on
18th Jan 2017
by
我是 python 正则表达式的新手,不确定如何仅提取日期部分。有什么建议么?
使用的代码:
from bs4 import BeautifulSoup as soup
import requests
from datetime import datetime
import pandas as pd
url='https://www.zoopla.co.uk/for-sale/property/petts-wood/?page_size=100'
req=requests.get(url)
page_soup = soup(req.content,'html.parser')
containers = page_soup.findAll('div',{'class':'listing-results-wrapper'})
e=containers[0].find('p',{'class':'top-half listing-results-marketed'})
【问题讨论】: