我有簡單的PhantomJS
腳本來解析Javascript
網站的內容到html
。 (有些數據隨後使用其他工具html
代碼中提取。)使用PhantomJS選擇菜單項
var page = require('webpage').create();
var fs = require('fs');// File System Module
var output = '/tmp/sourcefile'; // path for saving the local file
page.open('targeturl', function() { // open the file
fs.write(output,page.content,'w'); // Write the page to the local file using page.content
phantom.exit(); // exit PhantomJs
});
這用來工作時所有目標有直接聯繫。現在,他們是同一個URL後面,有下拉菜單:
<select id="observation-station-menu" name="station" onchange="updateObservationProductsBasedOnForm(this);">
<option value="101533">Alajärvi Möksy</option>
...
<option value="101541">Äänekoski Kalaniemi</option>
</select>
這是菜單項我真的喜歡加載:
<option value="101632">Joensuu Linnunlahti</option>
因爲這個菜單的我的腳本只下載相關數據到默認位置。如何從菜單中加載其他項目的內容並下載該項目的內容html
?
我的目標網站是這樣的:http://ilmatieteenlaitos.fi/suomen-havainnot
(如果有一個以上PhantomJS
這樣做,我可以使用它,以及更好的辦法我的興趣是在處理數據一旦得到它刮掉,我選擇了PhantomJS
。 。只是因爲它是工作的第一件事情,因爲我的服務器是一個Raspberry Pi
某些選項可能受到限制,可能無法在它的工作:Python Selenium: Firefox profile error)
這與其他答案類似。傳遞沒有錯誤,但包含默認選擇的數據。 –
我更新瞭解決方案,也許是因爲這個原因。 – user5542121
解決了它,謝謝! –