因此,我的所有页面内容都包含:
content = driver.page_source
soup = BeautifulSoup(content, features="html.parser")
然后,我做了这个:
idioma = soup.select(".idioma > span:nth-child(1)")
这给了我这个:
[<span>
<img alt="Idioma Aleman" class="post_flagen" src="https://www.gamestorrents.nu/wp-content/themes/GamesTorrent/css/images/flags/ale.png" title="Idioma Aleman"/>
<img alt="Idioma Chino-tradicional" class="post_flagen" src="https://www.gamestorrents.nu/wp-content/themes/GamesTorrent/css/images/flags/chi.png" title="Idioma Chino-tradicional"/>
<img alt="Idioma Coreano" class="post_flagen" src="https://www.gamestorrents.nu/wp-content/themes/GamesTorrent/css/images/flags/cor.png" title="Idioma Coreano"/>
<img alt="Idioma Español" class="post_flagen" src="https://www.gamestorrents.nu/wp-content/themes/GamesTorrent/css/images/flags/esp.png" title="Idioma Español"/>
<img alt="Idioma Español-latino" class="post_flagen" src="https://www.gamestorrents.nu/wp-content/themes/GamesTorrent/css/images/flags/esp.png" title="Idioma Español-latino"/>
<img alt="Idioma Frances" class="post_flagen" src="https://www.gamestorrents.nu/wp-content/themes/GamesTorrent/css/images/flags/fra.png" title="Idioma Frances"/>
<img alt="Idioma Ingles" class="post_flagen" src="https://www.gamestorrents.nu/wp-content/themes/GamesTorrent/css/images/flags/ing.png" title="Idioma Ingles"/>
<img alt="Idioma Italiano" class="post_flagen" src="https://www.gamestorrents.nu/wp-content/themes/GamesTorrent/css/images/flags/ita.png" title="Idioma Italiano"/>
<img alt="Idioma Portugues" class="post_flagen" src="https://www.gamestorrents.nu/wp-content/themes/GamesTorrent/css/images/flags/por.png" title="Idioma Portugues"/>
<img alt="Idioma Ruso" class="post_flagen" src="https://www.gamestorrents.nu/wp-content/themes/GamesTorrent/css/images/flags/rus.png" title="Idioma Ruso"/>
</span>]
当我这样做以获得头衔时:
idioma = [''.join(elem.find('img')['title']) for elem in idioma if elem]
我只得到了第一个
['Idioma Aleman']
为什么我不能把所有人都弄到手
要使用Selenium和python从所有
<span>
中提取title和src属性,必须为visibility_of_all_elements_located()
诱导WebDriverWait,并且可以使用以下任一Locator Strategies:对标题使用
CSS_SELECTOR
:对src使用
XPATH
注意:您必须添加以下导入:
为什么你得不到所有冠军?
这是因为在惯用语中只有一个元素,而您使用的
find()
只能获得第一个匹配项您可以这样做:
输出
根据评论添加工作示例
以下是不同之处:
相关问题 更多 >
编程相关推荐