在Python BeautifulSoup中查找div类的Parent Attributes

时间:2018-05-12 16:26:56

标签: python beautifulsoup

    soup = BeautifulSoup(code below, "html.parser")

    <item class="info" data="findthisinfo" example="exa1">

    <div class="exampleclass">
    EXAMPLE INFO
    </div>


    <item class="info" data="findthisinfo1" example="exa0">

    <div class="exampleclass">
    EXAMPLE INFO 2
    </div>

    <item class="info" data="findthisinfo2" example="exa2">

    <div class="exampleclass">
    SOME TEXT
    </div>

    for example in soup.find_all('item', attrs={'class': 'info'}):
        examp2 = example.find_all('div', attrs={'class': 'exampleclass'})
        examp3 = soup('div', text=re.compile("EXAMPLE"))

这给了我输出:

[EXAMPLE]
[EXAMPLE]
[]

我现在想找到两个特定输出的父类,所以例如我需要data="findthisinfo"data="findthisinfo1"的父值

我将如何做到这一点?

0 个答案:

没有答案