我在愤怒试图解析以下代表HTML提取物,使用BeautifulSoup和LXML:Python的 - 解析HTML类
[<p class="fullDetails">
<strong>Abacus Trust Company Limited</strong>
<br/>Sixty Circular Road
<br/>DOUGLAS
<br/>ISLE OF MAN
<br/>IM1 1SA
<br/>
<br/>Tel: 01624 689600
<br/>Fax: 01624 689601
<br/>
<br/>
<span class="displayBlock" id="ctl00_ctl00_bodycontent_MainContent_Email">E-mail: </span>
<a href="mailto:[email protected]" id="ctl00_ctl00_bodycontent_MainContent_linkToEmail">[email protected]</a>
<br/>
<span id="ctl00_ctl00_bodycontent_MainContent_Web">Web: </span>
<a href="http://www.abacusiom.com" id="ctl00_ctl00_bodycontent_MainContent_linkToSite">http://www.abacusiom.com</a>
<br/>
<br/><b>Partners(s) - ICAS members only:</b> S H Fleming, M J MacBain
</p>]
我想要做什么:
提取物 '强'文成COMPANY_NAME
提取物 'BR' 标记文本company_line_x
提取 'MainContent_Email' 文本company_email
提取 'MainContent_Web' 文本company_web
我有这些问题:
1)I可以提取通过使用.findall所有文本(文本= True),但每行有很多填充
2)非ASCII字符有时被返回,这会导致csv.writer失败..我不是100%确定如何处理这个正确。 (我以前只是用unicodecsv.writer)
任何意见将非常感谢!
此刻,我的功能只是接收页面数据,并使用findall()
隔离“P级”
def get_company_data(page_data):
if not page_data:
pass
else:
company_dets=page_data.findAll("p",{"class":"fullDetails"})
print company_dets
return company_dets
如何获取页面数据? – alecxe 2014-09-02 12:01:22
感谢您的回复。我使用请求模块提取数据,并将页面数据传递给此函数 – 2014-09-02 12:25:42
好的,您使用的是响应文本还是内容属性? – alecxe 2014-09-02 12:49:35