【发布时间】:2020-06-26 06:19:45
【问题描述】:
我想将它们全部打印为顶部 div 中给定站点的一类 div。这将是我有兴趣打印的网站 html 的一部分
<div class="game">
<div class="history-feed__collection">
<div class="history-feed__card h-card h-card_sm h-card_spades" style="width: 41px; margin-right: 18px; opacity: 1;">
<div class="h-card__sign">9</div></div>
<div class="history-feed__card h-card h-card_sm h-card_hearts" style="width: 41px; margin-right: 18px; opacity: 1;">
<div class="h-card__sign">K</div></div>
<div class="history-feed__card h-card h-card_sm h-card_diamonds" style="width: 41px; margin-right: 18px; opacity: 1;">
<div class="h-card__sign">Q</div></div>
<div class="history-feed__card h-card h-card_sm h-card_clubs" style="width: 41px; margin-right: 18px; opacity: 1;">
<div class="h-card__sign">2</div>
</div></div>
Eu gostaria que o programa imprimisse assim: “历史-feed__card h-card h-card_sm h-card_spades, history-feed__card h-card h-card_sm h-card_hearts, ……”
我启动了这段代码,但我仍然发现问题, 因为代码只打印 Div 中包含的内容,而不是其类的名称
from selenium import webdriver
driver = webdriver.Chrome(executable_path='C:\chromedriver')
driver.get('https://card.com')
id = driver.find_elements_by_xpath('//*[@class]')
for ii in id:
print(ii.get_attribute('class="hilo-history-feed__collection"'))
driver.close()
【问题讨论】:
-
嗨 Gustavo,仅在手机上,但您尝试过美味的汤:crummy.com/software/BeautifulSoup/bs4/doc 吗?你可能想使用‘find_all(“div”)’,然后是‘get(“class”)’。
-
看起来他们正在使用 Bootstrap...
-
我会看看文档来完成我的项目,谢谢
标签: python html web-scraping