Java generates images and regular expressions in extracting urls

1,    https://blog.csdn.net/qq_24076135/article/details/78045034

2.     http://www.vogella.com/tutorials/JavaRegularExpressions/article.html#java-regex-examples

3.     https://www.w3cschool.cn/java/java-regex-character-classes.html

4. Extract the document content:

package com.happySpider;

import java.io.*;
import java.net.*;


public class Main {

public static void main(String[] args) {
String urlTarget = "http://yun.52tencent.com:808/api/simple/nuomi/eat/meishi/2";
String happyOutputPath = "D:/happySpider/" ;
try {
URL happyUrl = new URL(urlTarget);//URl object
URLConnection happyConnect = happyUrl.openConnection();//Create a link
InputStream happyStream = happyConnect.getInputStream();//Create as a byte stream

BufferedReader/*Cache¥ class*/ happyBuffer = new BufferedReader(new InputStreamReader(happyStream,"UTF-8"));//Byte stream encoding format converts byte stream to character stream buffer
PrintWriter happyOutputFile = new PrintWriter/ *Save the file*/(new File(happyOutputPath+System.currentTimeMillis()/*Time converted to milliseconds and never repeated*/+".doc"));
String happyLine;
while((happyLine = happyBuffer.readLine ()/* read line by line */) != null)
{

System.out.println(happyLine);
happyOutputFile.println(happyLine);
}
happyOutputFile.close();
happyBuffer.close();
}
catch(IOException ex){//Define an input and output exception object called ex
ex.printStackTrace ();
}
}
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325297817&siteId=291194637