1
我正在写一个抓取职位的Python脚本。在列表中类职位的例子是这样的:获取元素的祖父类 - Python Selenium
抓住任何关键字,如夏季或在这种情况下,我抓住了这个称号独立,我使用的XPath看起来像这样:
temp = web.find_elements_by_xpath("//*[contains(text(), 'Summer 2016 Co-op - Software Test Engineer Intern')]")
我想抓住显示它的位置的文本,而不是试图抓住那个具体位置,因为每个工作都会在我的程序中发生变化。基本上,我想抓住爷爷类,并选择包含作业的位置DIV类(或只是抢在同一个父类中的其他元素),然而,使用XPath与“..”和
web.get_attributes('outerHTML')
只返回当前类而不是整个列表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>**
如何获得最高的父类(列表),甚至获得其他分区类?