LoginSignup
24
24

More than 5 years have passed since last update.

Electronでのクローラ開発

Posted at

ElectronってChromiumベースなので、クローラ開発にも使えるのではないかと試行錯誤してみる。
都度加筆する予定。

main.js
  mainWindow = new BrowserWindow({
    preload: path.resolve(path.join(__dirname, 'preload.js'))
  });

こんなふうに書くと、ページ遷移する度に[preload.js]が実行されるようになる。

画面制御

URLベースでやってみる

preload.js
window.onload = function(){
  if(location.href=="https://search-engine.co.jp"){
    //検索画面での処理
    $('#search-box').val('ことり')
    $('#search-form').submit()
  }else if(~location.href.indexOf('https://www.search-engine.co.jp/search?')){
    //検索結果での処理

    //中略

    ipcRenderer.send('writeCSV',result);
  }
}

他にもDBとかファイルとかlocalStorageとかに状態をもたせたりして制御もできそう。

プロキシ

main.js
app.commandLine.appendSwitch('proxy-server','xxx.xxx.xxx.xxx:80');

こんな感じで設定はできる。BrowserWindow毎にプロキシサーバを指定したい場合はどうするんだろう...

24
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
24