請教各位爬蟲界的先進,如何讓Rselenium找到下拉式選單中對應的網頁。
幾週前我發問了如何把 QuickFS 網頁的表格爬下來。在這個網站裡,每支股票有自已的一個網址,同一個網址下有5個頁面 (Overview, Income Statement, Balance sheet,
Cash flow statement, Key ratios),由一個右上角的拉下式選單來決定。網頁的特點
是,不論你到那個選項,網址都是一樣的。
我目前的進度是可以把主要頁面 (選單中的選項= Overview) 中所有表格爬下來。接著,我想讓Rselenium可以到選單中的每個選項頁面把所有表格爬下來。我參考了幾篇stackoverflow上提供的code, 但還沒有一個能適用於我想爬的網頁。感覺可能的方法至少有兩個,一是findElement()這個function把選單中的id及值取出; 另一個是把對應選單的element的
xpath烤下來,再套用某個function裡。第一個我試了error, 第二個我也不知道如何寫
xpath.
我把我的R程式, 及java, chrome driver的設定放在我的hackMD上面 。希望先進們指教。
![](https://i.imgur.com/fhiamGY.png</p><p>%E9%81%B8%E5%9D%80%E6%98%AF%20<img%20src=)
裡面有三個部分
(1) Connect Chrome driver, RSelenium
(2) Scrape all tables of the webpage where dropdown option is “Overview”
(3) Scrape tables on the webpage where dropdown option is “Income Statement
” (not working)
我預到的問題是放在最後一個部分。目前我只能把我認為是和選單中選項相對應的
elements烤下來,期待有人能教我如何讓 RSelenium進到對應的網頁裡拿表格。以下
的網頁程式碼看起來就是選單中的5個選項。我不解為何
con$findElement(using = 'id', value = 'ovr')
會error
<a _ngcontent-c4='' id='ovr'>Overview</a>
</li><li _ngcontent-c4=''>
<a _ngcontent-c4='' id='is'>Income Statement</a>
</li><li _ngcontent-c4=''>
<a _ngcontent-c4='' id='bs'>Balance Sheet</a>
</li><li _ngcontent-c4=''>
<a _ngcontent-c4='' id='cf'>Cash Flow Statement</a>
</li><li _ngcontent-c4=''>
<a _ngcontent-c4='' id='ratios'>Key Ratios</a>
想學RSelenium爬蟲但還沒開始的朋友們,可以參考第1及2部分裡的步驟。
感謝。
--