【发布时间】:2017-03-25 10:14:37
【问题描述】:
我正在使用带有 python 的 bs4 并尝试从网页中获取数据。 Link 我在我想要的信息上使用了检查元素,但两者都有相同的标签、类。
<a class="cell__value" data-tracker-action="click" data-tracker-label="information_technology.01" href="/markets/sectors/information-technology">
Information Technology
</a>
</div>
<div class="cell__return">
<div class="cell__label">
% Price Change
</div>
<div class="cell__value" data-type="better">
+0.05%
</div>
</div>
</div>
<div class="cell">
<div class="cell__name">
<div class="cell__label">
Industry
</div>
<a class="cell__value" data-tracker-action="click" data-tracker-label="information_technology.02" href="/markets/sectors/information-technology">
Software & Services
</a>
</div>
<div class="cell__return">
<div class="cell__label">
% Price Change
</div>
<div class="cell__value" data-type="worse">
-0.04%
</div>
</div>
</div>
</div>
我是这样做的:
sect= soup.find("a",{"data-tracker-label":"information_technology.01"})
print sect.text
sect_per= soup.find("div",{"data-type":"worse"or"better"})
print sect_per.text
ind=soup.find("a",{"data-tracker-label":"information_technology.02"})
print ind.text
ind_per=soup.find("div",{"div",{"data-type":"worse"or"better"})
print ind_per
both print ind_per 和 print ind_per 由于相同的班级和标签
我需要提取+0.05%和-0.04%分别。 >
请给我建议。
【问题讨论】:
标签: python web-scraping beautifulsoup