擅长:python、mysql、java
<p>我建议使用<strong>pandas</strong>到<code>read_html()</code>并加载到<code>DataFrame</code>,然后导入到<strong>csv</strong></p>
<p>如果你没有熊猫。非常简单的安装步骤</p>
<blockquote>
<p>pip install pandas</p>
</blockquote>
<p><strong>代码</strong>:</p>
<pre><code>import pandas as pd
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
driver=webdriver.Firefox(executable_path="path\to\gecodriver")
driver.get("https://www.bankier.pl/inwestowanie/profile/quote.html?symbol=CCC")
table=WebDriverWait(driver,15).until(EC.visibility_of_element_located((By.CSS_SELECTOR,".marketInfo"))).get_attribute("outerHTML")
df=pd.read_html(str(table))[0]
df.to_csv("scraper.csv",index=False)
</code></pre>
<p>生成后的Csv文件</p>
<p><a href="https://i.stack.imgur.com/nBfLN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nBfLN.png" alt="enter image description here"/></a></p>