当前位置: 代码迷 >> Ruby/Rails >> 99公寓四六级成绩查询模拟ruby版本和curl版本
  详细解决方案

99公寓四六级成绩查询模拟ruby版本和curl版本

热度:176   发布时间:2016-04-29 02:21:01.0
99宿舍四六级成绩查询模拟ruby版本和curl版本

一.ruby版本,需要使用curb gem

# encoding: UTF-8require 'curb'#99宿舍网页是GBK的CET_NUM = "xxxxxxxxxxxx"CET_NAME = "xxxx".encode('gb2312', 'utf-8')user = {  :name => CET_NAME,  :id => CET_NUM}get_score_url = "http://cet.99sushe.com/find"curl = Curl.post(get_score_url, user) do |h|  h.headers["Referer"] = "http://cet.99sushe.com/"endcet = curl.body.encode("utf-8", "gb2312")puts cet.split(",")

二.curl版本,需要配合ruby转码

# encoding: UTF-8require 'open-uri'CET_NUM = "xxxxxxxxxxxx"CET_NAME = "xxxx".encode('gb2312', 'utf-8')cet_name = URI::encode CET_NAMEget_score_url = "http://cet.99sushe.com/find"result = `curl 'http://cet.99sushe.com/find' -H 'Referer: http://cet.99sushe.com/' --data 'id=#{CET_NUM}&name=#{cet_name}'`result = result.encode('utf-8', 'gb2312')cet_result = result.split(",")

?