我在写一个Python脚本来获取职位头衔。列表类中的职务示例如下所示:
为了获取诸如Summer之类的关键字,或者在本例中,我分别使用了xpath,如下所示:
temp = web.find_elements_by_xpath("//*[contains(text(), 'Summer 2016 Co-op - Software Test Engineer Intern')]")
我想抓取文本,显示它在哪里,而不是试图抓住具体的,因为每个工作将在我的程序变化。基本上,我想获取grandian类并选择包含作业位置的div类(或者只获取同一父类中的其他元素),但是,使用xpath和“..”和
^{2}$只返回当前类而不是整个list div类。在
这个div类的代码如下所示:
<li class="row list-item list_rows" id="row_3b11ddb0571c6c4908b2cca98804ec00">
<div class="list-item-logo">
<a href="https://rit-csm.symplicity.com/students/index.php?s=employers&mode=profile&id=c2c0dd779fe969740566778ee0816177&ss=jobmatches"><img src="./job postings _ RIT Job Zone_files/view.php" alt="Logo" class="avatar avatar-square"></a>
</div>
<div class="list-item-body">
<div class="list-item-title">
**<a href="https://rit-csm.symplicity.com/students/index.php?mode=form&id=3b11ddb0571c6c4908b2cca98804ec00&s=jobs&ss=jobmatches" class="ListPrimaryLink">Summer 2016 Co-op - Software Test Engineer Intern</a>**
</div>
<div class="list-data-columns">
Co-op
</div>
<div class="list-data-columns">
<a href="https://rit-csm.symplicity.com/students/index.php?s=employers&ss=list&mode=profile&id=c2c0dd779fe969740566778ee0816177" class="ListPrimaryLink">Veson Nautical</a> - Boston, Massachusetts<br>Lebanon, New Hampshire
</div>
</div>
</div>
</div>
</li>
显然没有加粗的那一行是通过使用xpath代码行选择的。在
**<a href="https://rit-csm.symplicity.com/students/index.php?mode=form&id=3b11ddb0571c6c4908b2cca98804ec00&s=jobs&ss=jobmatches" class="ListPrimaryLink">Summer 2016 Co-op - Software Test Engineer Intern</a>**
我怎样才能得到最高的父类(列表)甚至其他div类呢?在
与xpath只选择
a
标记不同,您可以使用一个包含元素的祖先的xpath(例如li
)。在相关问题 更多 >
编程相关推荐