“烟花”二次登陆!请持续关注天气变化
程序员文章站
2022-05-29 12:09:08
...
近期各地暴雨引起的灾害让人感到痛心,请及时通过天气预报信息关注台风动态。台风“烟花”将再次登陆浙江平湖,预计“烟花”将以每小时10公里左右的速度向西北方向移动,强度逐渐减弱,28日将转向东北方向移动,30日移入黄海海面。“烟花”将引起局部地区的暴雨,请大家外出注意安全。相关信息从http://www.weather.com.cn实时采集获取,示例如下:
import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; public class Demo { public static void main(String[] args) { try{ // 代理服务器(产品官网 www.16yun.cn) final static String ProxyHost = "t.16yun.cn"; final static String ProxyPort = "31111"; System.setProperty("http.proxyHost", ProxyHost); System.setProperty("https.proxyHost", ProxyHost); System.setProperty("http.proxyPort", ProxyPort); System.setProperty("https.proxyPort", ProxyPort); // 代理验证信息 final static String ProxyUser = "username"; final static String ProxyPass = "password"; System.setProperty("http.proxyUser", ProxyUser); System.setProperty("http.proxyPassword", ProxyPass); System.setProperty("https.proxyUser", ProxyUser); System.setProperty("https.proxyPassword", ProxyPass); // 设置IP切换头 final static String ProxyHeadKey = "Proxy-Tunnel"; // 设置Proxy-Tunnel Random random = new Random(); int tunnel = random.nextInt(10000); String ProxyHeadVal = String.valueOf(tunnel); // 处理异常、其他参数 String url=“http://www.weather.com.cn”; Document doc = Jsoup.connect(url).timeout(3000).header(ProxyHeadKey, ProxyHeadVal).get(); if(doc != null) { System.out.println(doc.body().html()); } }catch (IOException e) { e.printStackTrace(); } } }