获取元素的祖父类-Python Selenium

获取元素的祖父类-Python Selenium,python,selenium,xpath,selenium-webdriver,selenium-chromedriver,Python,Selenium,Xpath,Selenium Webdriver,Selenium Chromedriver,我正在写一个Python脚本来获取工作头衔。列表类中的职务名称示例如下所示: 为了抓取任何关键字,例如Summer,或者在本例中,我单独抓取了这个标题,我使用了xpath,如下所示: temp = web.find_elements_by_xpath("//*[contains(text(), 'Summer 2016 Co-op - Software Test Engineer Intern')]") <li class="row list-item list_rows" i

我正在写一个Python脚本来获取工作头衔。列表类中的职务名称示例如下所示:

为了抓取任何关键字,例如Summer,或者在本例中,我单独抓取了这个标题,我使用了xpath,如下所示:

    temp = web.find_elements_by_xpath("//*[contains(text(), 'Summer 2016 Co-op - Software Test Engineer Intern')]")
<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&amp;mode=profile&amp;id=c2c0dd779fe969740566778ee0816177&amp;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&amp;id=3b11ddb0571c6c4908b2cca98804ec00&amp;s=jobs&amp;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&amp;ss=list&amp;mode=profile&amp;id=c2c0dd779fe969740566778ee0816177" class="ListPrimaryLink">Veson Nautical</a> - Boston, Massachusetts<br>Lebanon, New Hampshire               
                 </div>                                                                                                                                                                             
              </div>     
            </div>
        </div>
    </li>
我想抓取显示其位置的文本,而不想特别抓取,因为我的程序中的每个作业都会发生变化。基本上,我想抓取祖父类并选择包含作业位置的div类(或者只抓取同一父类中的其他元素),但是,使用带“…”和“…”的xpath

web.get_attributes('outerHTML')
仅返回当前类,而不是整个list div类

此div类的代码如下所示:

    temp = web.find_elements_by_xpath("//*[contains(text(), 'Summer 2016 Co-op - Software Test Engineer Intern')]")
<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&amp;mode=profile&amp;id=c2c0dd779fe969740566778ee0816177&amp;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&amp;id=3b11ddb0571c6c4908b2cca98804ec00&amp;s=jobs&amp;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&amp;ss=list&amp;mode=profile&amp;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&amp;id=3b11ddb0571c6c4908b2cca98804ec00&amp;s=jobs&amp;ss=jobmatches" class="ListPrimaryLink">Summer 2016 Co-op - Software Test Engineer Intern</a>** 
    
    ***
    

    如何获得最高的父类(列表)或甚至获得其他div类

    不必使用只选择
    a
    标记的xpath,您可以使用获取元素某个祖先的xpath(例如
    li


    不必使用只选择
    a
    标记的xpath,您可以使用接受元素某个祖先的xpath(例如
    li