循环网页R.

时间:2015-10-19 18:23:40

标签: r loops web-scraping

我想应用一个循环从R中的多个网页中抓取数据。我正在运行下一个代码:

    Socket socket = new Socket(data.getIp(), data.getTcpPort());
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    // OutputStream os = null;

    // send file
    File myFile = new File(data.getFileName());
    String test = myFile.getAbsolutePath();
    byte[] mybytearray = new byte[(int) myFile.length()];
    fis = new FileInputStream(myFile);
    bis = new BufferedInputStream(fis);
    bis.read(mybytearray, 0, mybytearray.length);
    ObjectOutputStream os = new ObjectOutputStream(
            new BufferedOutputStream(socket.getOutputStream()));
    os.flush();
    System.out.println("Sending " + data.getFileName() + "("
            + mybytearray.length + " bytes)");
    if (os != null) {
        os.writeInt(mybytearray.length);
        os.write(mybytearray, 0, mybytearray.length);
        os.flush();
        System.out.println("Done.");
    }
    if (bis != null) {
        bis.close();
    }
    if (os != null) {
        os.close();
    }
    if (socket != null) {
        socket.close();

    }

但我有这样的信息:

错误:意外','在: " for(i in city){   url< - (" http://www.washingtongasprices.com/GasPriceSearch.aspx?typ=adv&fuel=D&srch=0&area=","

我该如何解决?

1 个答案:

答案 0 :(得分:2)

您需要将网址粘贴在一起

url <- paste0("http://www.washingtongasprices.com/GasPriceSearch.aspx?typ=adv&fuel=D&srch=0&area=",i,"&site=Washington&station=All%20Stations&tme_limit=36")