【发布时间】:2017-03-14 11:41:27
【问题描述】:
我正在按照指南 (http://docs.python-guide.org/en/latest/scenarios/scrape/) 抓取网站 (https://www.brookfieldproperties.com/portfolio/toronto/bay-adelaide-east/) 并浏览了 lxml 包网站,但不知道出了什么问题。
我有这个代码:
from lxml import html
import requests
page = requests.get('https://www.brookfieldproperties.com/portfolio/toronto/bay-adelaide-east/')
tree = html.fromstring(page.content)
floor = tree.xpath('//div[@class="column floor"]/text()')
sf = tree.xpath('//div[@class="column rsf"]/text()')
但是 floor 和 sf 返回 '\n\t\t\t\t' 值的列表,而不是您期望查看的整数来自实际网站的 html(以下情况下为“20”和“5117”):
<div class="availabilityWrap">
<h3>Availabilities</h3>
<div class="availabilityRow headerRow">
<div class="column floor">
<a href="/media/img/asset/pdf/BAC-ET-_20th_Floor_-_5100sf.pdf"
target='blank'><img src="/static/images/pdf.png" class="floorPDF" />20</a>
</div>
<div class="column rsf">
<p><b>5117</b></p>
</div>
<div class="column divisible">
<p><b>yes</b></p>
</div>
<div class="column date">
<p><b>05/01/2017</b></p>
</div>
<div class="column space">
<p><b>Office</b></p>
</div>
<div class="column description">
<p><b>model suite</b></p>
</div>
<div class="column rent">
<p><b>$26.55</b></p>
</div>
</div>
不应该只返回“column floor” div 类中的所有文本吗?任何帮助都会很棒。
【问题讨论】:
标签: python html web-scraping lxml