- 论坛徽章:
- 0
|
写了小程序,抓baidu的新闻玩,但是后来,居然出现了403错误,再也无法登陆baidu的新闻页面了。
不知道baidu是怎么限制的,多久才重新开放我的IP啊
java写的小程序。
- con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
- con.connect();
-
- int httpResult = con.getResponseCode();
- System.out.println(httpResult);
-
- if(httpResult == 200)
- {
-
- java.io.InputStream urlStream = con.getInputStream();
- //将获得的字符流放进缓冲里
- BufferedReader reader = new BufferedReader(new InputStreamReader(urlStream));
- while((sCurrentLine = reader.readLine()) != null) //逐行读取
- {
- sTotalString.append(sCurrentLine+"\r\n"); //将每一行添加到临时变量
- }
-
- createFile(sTotalString);
- }
复制代码 |
|