【发布时间】:2019-05-21 03:45:50
【问题描述】:
我正在抓取一个游戏网站,我想获取包含特定文本的 div 对象。 在这种情况下,我想获取包含带有文本“SANDBOX Ghost”的 href 的 div 类“GameItemWrap”。 整个代码中有很多 GameItemWrap 类,我不想获取“SummonerName”类 div,因为“GameItemWrap”中还有一些其他类是我需要的。
这是我尝试过的:
duo_name='SANDBOX Ghost'
gamelist=soup.find('div',"GameItemList")# "GameItemList" is a div that contains "GameItemWrap"
games=gamelist.find_all('GameItemWrap',{('a'):duo_name })
这就是我正在抓取的 javascript 的样子:
<div class="GameItemWrap>
#some other div classes that i will need in the future
<div class="SummonerName">
<a href="//www.op.gg/summoner/userName=SANDBOX+Ghost" class="Link" target="_blank">SANDBOX Ghost</a>
</div>
</div>
我期待 4 个包含文本“SANDBOX Ghost”的 GameItemWrap 但是当我打印时
print(len(games))
输出为 0。这不起作用。 另外我不想检查每个 GameItemWraps 类来检查它们是否包含“SANDBOX Ghost” 这可能吗?
【问题讨论】:
标签: python web-scraping beautifulsoup