Re: [ruby] http client parser
標題Re: [ruby] http client parser
時間北極光 (2010/06/16 Wed 09:58:50)
※ 引述《Tony1223 (沉默是金)》之銘言:
<font class="A03640">> id="xxx"> pwd="yyy"> require 'httpclient'> clnt = HTTPClient.new> clnt.set_cookie_store('cookie.dat')> clnt.get_content("https://xxxxx.com/login/")> body = { 'email' => id, 'password' => pwd ,"rememberme" =>"no" , "referrer" => ""}> #登入行為> clnt.post("https://xxxxxxxx.com/login/", body)> res = clnt.get_content("http://xxxxxxx.com/the_target_url")> #字串分析> puts res.scan(/class="xxxx">(.*?)<\/td>/m)> 其實還蠻輕鬆愉快的> 比起 java httpclient的話,缺點就是要裝 ruby gem .</font><font class="A03740">
後來發現有更輕鬆愉快的神兵利器
Nokogiri(鋸子)
介紹
http://ithelp.ithome.com.tw/question/10036858?tag=rt.rq
官網
http://nokogiri.org/
可以用 css selector 來做html parse ,
應該沒有比這更威的了吧 XD
--
▄▅▆▇███▇▆▅▄▃ ╰┼╯─╮ ╮
◥███████████◣ ╰┼╯=│=│
◥██████───────◣ *. ╯ ╯ ╯ の 物 語 .*
◥███████──────◣ ~ ◢◣ ◢◣
◥██████───────◤ ◥◤* 空白的世界.翼 *◥◤
◥██▁▂▃▄▅▆▇███▆▅▄▃▂▂~telnet://tony1223.no-ip.info
--
╭═ Origin ─═ 北極光 aurora.twbbs.org κλμ ─╣
╚─ Author ═─ 114-136-231-45.dynamic.hi
</font>
Comments
No approved comments yet.