Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // get URL content
- url = new URL("http://www.sigmabeauty.com/f23-soft-angled-contour/p/F23");
- URLConnection conn = url.openConnection();
- // open the stream and put it into BufferedReader
- BufferedReader br = new BufferedReader(
- new InputStreamReader(conn.getInputStream()));
- String inputLine;
- String mydata="";
- //save to this filename
- String fileName = "test.html";
- File file = new File(fileName);
- if (!file.exists()) {
- file.createNewFile();
- }
- //use FileWriter to write file
- FileWriter fw = new FileWriter(file.getAbsoluteFile());
- BufferedWriter bw = new BufferedWriter(fw);
- while ((inputLine = br.readLine()) != null) {
- bw.write(inputLine);
- mydata+=inputLine;
- }
- // Pattern pattern = Pattern.compile("itemprop=\\\"(\\S+)\\\".*?>(.*)?<");
- // Pattern pattern = Pattern.compile("itemprop=\\\"(\\S+)\\\".*?>.*?<");
- Pattern pattern = Pattern.compile("itemprop=\\\"name\\\".*?>.*?<");
- Matcher matcher = pattern.matcher(mydata);
- while(matcher.find()) {
- System.out.print("Found match:"+matcher.group(0));
- System.out.println("Input String matches regex - "+matcher.start()+matcher.end());
- }
- //System.out.println("Input String matches regex - "+matcher.find()+matcher.start()+matcher.end());
- bw.close();
- br.close();
- System.out.println("Done");
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement