许久不开车的我发现最近的油价疯狂的在涨呀,所以特地去了解了下新闻,原来随着国际原油价格不断攀升,全球各国加油站的汽油价格几乎都是水涨船高。数据显示,今年以来,国际原油价格飙涨了60%以上,与此同时,供各国消费者所使用的汽油价格自然也是水涨船高,真心的要开不起车啦。

今天我们就通过python来分析下汽油每天的价格数据,分析下油价是涨的幅度和后期是否有继续上涨的趋势。

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;

import java.io.IOException;

public class Main {
    # 代理服务器(产品官网 www.16yun.cn)
    private static final String PROXY_HOST = "t.16yun.cn";
    private static final int PROXY_PORT = 31111;

    public static void main(String[] args) {
        HttpClient client = new HttpClient();
        HttpMethod method = new GetMethod("https://data.eastmoney.com/cjsj/yjtz/default.html");

        HostConfiguration config = client.getHostConfiguration();
        config.setProxy(PROXY_HOST, PROXY_PORT);

        client.getParams().setAuthenticationPreemptive(true);

        String username = "16VOMFMQ";
        String password = "712323";
        Credentials credentials = new UsernamePasswordCredentials(username, password);
        AuthScope authScope = new AuthScope(PROXY_HOST, PROXY_PORT);

        client.getState().setProxyCredentials(authScope, credentials);

        try {
            client.executeMethod(method);

            if (method.getStatusCode() == HttpStatus.SC_OK) {
                String response = method.getResponseBodyAsString();
                System.out.println("Response = " + response);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            method.releaseConnection();
        }
    }
}

今年汽油涨价一大原因是我国的石油很大一部分是依赖进口的,所以国际原油价格在上涨的时候,产油成本变高,中石油为保障本身的利润,便把这一部分成本加到售价上,虽然是这样,但是再涨就开不起车了啦。