东南大学课程表爬虫
這是java 語言的,有python的如果要的話在評(píng)論區(qū)要把,直接上代碼~~
1 import java.io.BufferedReader; 2 import java.io.IOException; 3 import java.io.InputStream; 4 import java.io.InputStreamReader; 5 import java.io.OutputStreamWriter; 6 import java.net.URL; 7 import java.net.URLConnection; 8 9 public class seuCrawl { 10 11 public static void testPost() throws IOException { 12 13 //連接地址 14 String surl = "http://xk.urp.seu.edu.cn/jw_service/service/stuCurriculum.action"; 15 16 /** 17 * 首先要和URL下的URLConnection對(duì)話。 URLConnection可以很容易的從URL得到。比如: // Using 18 * java.net.URL and //java.net.URLConnection 19 */ 20 URL url = new URL(surl); 21 URLConnection connection = url.openConnection(); 22 23 /** 24 * 然后把連接設(shè)為輸出模式。URLConnection通常作為輸入來使用,比如下載一個(gè)Web頁。 25 * 通過把URLConnection設(shè)為輸出,你可以把數(shù)據(jù)向你個(gè)Web頁傳送。下面是如何做: 26 */ 27 connection.setDoOutput(true); 28 /** 29 * 最后,為了得到OutputStream,簡(jiǎn)單起見,把它約束在Writer并且放入POST信息中,例如: ... 30 */ 31 OutputStreamWriter out = new OutputStreamWriter(connection 32 .getOutputStream(), "UTF-8"); 33 String submitInfo = "queryStudentId="+"2131335"+"&"+"stuCurriculum_queryAcademicYear="+"14-15-2"; 34 out.write("queryStudentId=2131335&stuCurriculum_queryAcademicYear=14-15-2"); //post的關(guān)鍵所在! 35 // remember to clean up 36 out.flush(); 37 out.close(); 38 /** 39 * 這樣就可以發(fā)送一個(gè)看起來象這樣的POST: 40 * POST /jobsearch/jobsearch.cgi HTTP 1.0 ACCEPT: 41 * text/plain Content-type: application/x-www-form-urlencoded 42 * Content-length: 99 username=bob password=someword 43 */ 44 // 一旦發(fā)送成功,用以下方法就可以得到服務(wù)器的回應(yīng): 45 String sCurrentLine; 46 String sTotalString; 47 sCurrentLine = ""; 48 sTotalString = ""; 49 InputStream l_urlStream; 50 l_urlStream = connection.getInputStream(); 51 // 傳說中的三層包裝阿! 52 BufferedReader l_reader = new BufferedReader(new InputStreamReader( 53 l_urlStream)); 54 while ((sCurrentLine = l_reader.readLine()) != null) { 55 sTotalString += sCurrentLine + "\r\n"; 56 57 } 58 System.out.println(sTotalString); 59 } 60 61 public static void main(String[] args) throws IOException { 62 63 testPost(); 64 65 } 66 67 }?
轉(zhuǎn)載于:https://www.cnblogs.com/fillim/p/4184653.html
總結(jié)
- 上一篇: cmd - 使用curl命令的注意点
- 下一篇: ajax-简单参数方法实现阴影效果