package com.zzk.cn;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.sql.*;
import java.util.Enumeration;
import java.util.Properties;
import net.sf.json.JSONObject;
/**
*
* @author zhuzhengke
* @version 1.0.0
*
*/
public class Json {
static String info = "";
/*主函数*/
public static void main(String[] args) throws UnsupportedEncodingException {
//抓取网页
getInfo(101010100);
//解析字段
readJson();
//insertMysql();
}
public class GetInfo {
public void getInfo(int id) {
String path = "http://m.weather.com.cn/data/"+id+".html";
URL url;
String inputline = "";
InputStream input = null;
InputStreamReader reader = null;
BufferedReader buffer = null;
try {
url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10 * 1000);
conn.setRequestMethod("GET");
input = conn.getInputStream();
reader = new InputStreamReader(input,"utf8");
buffer = new BufferedReader(reader);
while ((inputline = buffer.readLine()) != null) {
info += inputline;
}
} catch (ProtocolException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
天气预报之抓取、解析、存入MYSQL数据库模块实现,不规范(代码)
最新推荐文章于 2020-03-31 20:39:58 发布
该代码实现了一个天气预报的爬虫,抓取指定城市的天气信息,包括城市、日期、星期、温度、天气状况、风力等,并将数据解析后存储到MySQL数据库的weather_info表中。
摘要由CSDN通过智能技术生成