ラベル WEBスクレイピング の投稿を表示しています。 すべての投稿を表示
ラベル WEBスクレイピング の投稿を表示しています。 すべての投稿を表示

2012年8月17日金曜日

FileMaker + Internet Explorer Google翻訳、郵便番号から住所、amzonで検索



FileMaker で Internet Explorer を操作し、
Google Translateで翻訳結果を取得。
http://qbxxdp.blogspot.jp/2012/08/google-translate-filemaker.html
郵便番号から住所を取得。
http://qbxxdp.blogspot.jp/2012/08/filemakerinternet-explorer.html
amazonで検索し、商品情報を取得。
http://qbxxdp.blogspot.jp/2012/08/amazon-filemaker.html

要プラグイン
ScriptMakerMS
https://sites.google.com/site/scriptmakerms/scriptmakerms

要カスタム関数
WFM.fp7(ファイル内)
https://sites.google.com/site/scriptmakerms/scriptmakerms/web-scraping

動作環境
OS:Xp , 7
FileMaker 11

2012年8月10日金曜日

Google Translateで翻訳 + FileMaker

カスタム関数「Navigate_CreateObject 」を変更
Navigate_Create ( url ; visible )
名前を短縮して"visible"を追加。

例:
Navigate_Create ( http://translate.google.co.jp/#ja/en/ ; 0 )
visible=
表 示 : true
非表示 : false
表 示 : 1
非表示 : 0


要プラグイン
ScriptMakerMS
https://sites.google.com/site/scriptmakerms/scriptmakerms 

要カスタム関数
WFM.fp7(ファイル内)
https://sites.google.com/site/scriptmakerms/scriptmakerms/web-scraping 

動作環境
OS:Xp , 7
FileMaker 11

スクリプト名:GoogleTranslate(source)
{

変数を設定 [$source; 値:Get(スクリプト引数)]
レイアウト切り替え [「GoogleTranslate」 (GoogleTranslate)]
#Internet Explorerを探す
変数を設定 [$er; 値:Set_ie]
#Internet Explorerがない、または、Google Translateが開いていない場合、Google Translateへ移動
If [IsEmpty ( $er ) or PatternCount ( $er ; "http://translate.google.co.jp/#ja/en/" ) = 0]
変数を設定 [$er; 値:Navigate_Create ( "http://translate.google.co.jp/#ja/en/" ; 1)]
End If
変数を設定 [$er; 値:Wait4ie]
#結果の文字列をカラにする
変数を設定 [$er; 値:SetinnerTextById("result_box" ; "" )]
#翻訳したい文字を入力
変数を設定 [$er; 値:SetinnerTextById("source"; $source )]
#[翻訳ボタン]をクリック //通常は要らない
変数を設定 [$er; 値:ClickById("gt-submit") //[翻訳ボタン]をクリック //通常は要らない]
スクリプト一時停止/続行 [間隔(秒): 1]
#結果を取得
変数を設定 [$Result; 値:GetById ( "result_box"    ; "innerText" )]
変数を設定 [$n; 値:1]
Loop
Exit Loop If [ not IsEmpty ( $Result ) or $n>10]
変数を設定 [$Result; 値:GetById ( "result_box"    ; "innerText" )]
スクリプト一時停止/続行 [間隔(秒): 1]
変数を設定 [$n; 値:$n+1]
End Loop
フィールド設定 [GoogleTranslate::result_box; $Result]
現在のスクリプト終了 [結果: $Result]
}

変数を設定 [$er; 値:Navigate_Create ( "http://translate.google.co.jp/#ja/en/" ; 1)]
この部分のを
変数を設定 [$er; 値:Navigate_Create ( "http://translate.google.co.jp/#ja/en/" ; 0)] 
にするとInternet Explorerが表示されないのでFileMakerで翻訳をしているように見せかける事が出来ます。

Internet Explorerを隠している場合は、バックグラウンドで開きっぱなしになるので
iiil_Exe("ie.Quit();")
で終了する必要があります。

2012年8月8日水曜日

FileMakerからInternet Explorerを操作して郵便番号から住所を取得

FileMakerからInternet Explorerを操作して郵便番号から住所を取得!

カスタム関数「GetByClassName」を作ったので class="data" とかなっているタグのテキストの取得がカンタンになりました。


郵便番号検索 - 日本郵便 : http://www.post.japanpost.jp/zipcode/index.html
から郵便番号で検索して住所を取得します。

スクリプト名:GET郵便番号から住所(郵便番号)

変数を設定 [$zip; 値:Get(スクリプト引数)]
変数を設定 [$er; 値:Navigate_CreateObject ( "http://www.post.japanpost.jp/cgi-zip/zipcode.php?zip="  & $zip)]
変数を設定 [$er; 値:Wait4ie]
変数を設定 [$郵便番号; 値:GetByClassName ( "data" ; 0 ; "innerText" )]
変数を設定 [$都道府県; 値:GetByClassName ( "data" ; 1 ; "innerText" )]
変数を設定 [$市区町村; 値:GetByClassName ( "data" ; 2 ; "innerText" )]
変数を設定 [$町域; 値:GetByClassName ( "data" ; 3 ; "innerText" )]


「Navigate_CreateObject 」「GetByClassName」は、カスタム関数

要プラグイン
ScriptMakerMS
https://sites.google.com/site/scriptmakerms/scriptmakerms

要カスタム関数
WFM.fp7(ファイル内)
https://sites.google.com/site/scriptmakerms/scriptmakerms/web-scraping

動作環境
OS:Xp , 7
FileMaker 11

2012年8月3日金曜日

amazon からFileMakerへ情報取得

FileMakerからInternet Explorerを操作してamazonから情報を取得。

テスト環境
OS:Win Xp, 7
FileMaker Pro 11

プラグイン:ScriptMakerMS

画像は、ScriptMakerMSiiil_GetDataToFieldでフィールドへ直接入力(ダウンロード)
※実行は、FileMaker Pro 11, 12ならiiil_GetDataToFieldはなしでもOK!




WebFormMaker4ie.fmxの開発をやめ、WEBスクレイピングは、ScriptMakerMS+VBScriptでやっていましたが、JScriptに切りかえてさらにカスタム関数をりようしてさらに使いやすく?なった?かな?

カスタム関数
詳しい説明は、ScriptMakerMS|Webスクレイピング に書いていく予定。

ClickById ( id )
ClickByName ( name ; index )
ClickByTagName ( name ; index )
ClickLinkByInnerText ( keyword )
fmQuery ( Script )
GetByClassName ( className ; index ; element )
GetById ( id ; element )
GetByName ( name ; index ; element )
GetByTagName ( name ; index ; element )
JS_Esc ( Text )
Navigate_CreateObject ( url )
Set_ie
SetCheckedById ( id ; boolean )
SetCheckedByName ( name ; index ; boolean )
SetinnerTextById ( id ; value )
SetinnerTextByName ( name ; index ; value )
SetSelectedById ( id ; OptionIndex ; boolean )
SetSelectedByName ( name ; index ; OptionIndex ; boolean )
SetTarget ( element )
SetTargetByClassName ( className ; index )
Wait4ie

WebFormMaker4ie.fmxっぽく使えるかな?JScript(JabaScript)ベースなので機能が足りなければ、JScript(JabaScript)で記述して補える!

例えば、
GetById ( id ; element )
の中身は、
iiil_Eval( "
 if ( Target ) { 
     }else{
      Target=ie.document;
     }
    Target.getElementById( '" & id & "' )." & element & ";
")
このようになっているので、

<div id="hoge"> <img alt="" height="135" src="http://x.jpg" width="101" /> インナーテキスト </div>

GetById (  "hoge"  ; "innerText" ) 結果:インナーテキスト
GetById (  "hoge"  ; "firstChild.src" ) 結果:http://x.jpg
以下でも同じ
GetById (  "hoge"  ; "getElementsByTagName('img')[0].src" ) 結果:http://x.jpg

必要なら「iiil_Exe」「iiil_Eval」にJavaScriptを書けるので自由度が高い!

iiil_Exe( "ie.document.getElementsByTagName('a')[0].click()")
iiil_Eval( "ie.document.getElementsByTagName('img')[0].src ")


FileMaker + ScriptMakerMS + JScript(JabaScript) + カスタム関数で
Webスクレイピングがより楽ちん!になりそう!