【发布时间】:2021-12-01 12:49:21
【问题描述】:
我正在尝试从网页中获取硬币名称列表。 我试过用汤,但由于某些原因没有用。 并且还尝试使用硒。 :( 但也不工作。
那个网站有什么问题? (我发现了 javascript & DOM 问题?但看不清楚..) 我可以得到一些帮助以从网络上获取所有列表吗? (我使用 Chrome 驱动管理器来避免一些错误)
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from bs4 import BeautifulSoup
from selenium.webdriver.common.keys import Keys
import time
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
driver = webdriver.Chrome(ChromeDriverManager().install(),options=options)
html = driver.get('https://coinmarketcap.com/')
html = driver.page_source
driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")
driver.maximize_window()
driver.implicitly_wait(10)
soup = BeautifulSoup(html, 'html.parser')
status_today = soup.find_all('div',{'class':'sc-16r8icm-0 escjiH'},'href')
for x in status_today:
print('x.a[href]=',x.a['href'])
结果仅包含 10 行,有 100 个硬币列表...
x.a[href]= /currencies/bitcoin/
x.a[href]= /currencies/ethereum/
x.a[href]= /currencies/binance-coin/
x.a[href]= /currencies/cardano/
x.a[href]= /currencies/tether/
x.a[href]= /currencies/xrp/
x.a[href]= /currencies/solana/
x.a[href]= /currencies/polkadot-new/
x.a[href]= /currencies/usd-coin/
x.a[href]= /currencies/dogecoin/
【问题讨论】:
标签: python selenium beautifulsoup selenium-chromedriver