NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class TimeStoriesApp {

public static void main(String[] args) {
try {
// Fetch the Time.com webpage
String url = "https://time.com";
String htmlContent = fetchWebpage(url);

// Extract the latest stories from the HTML content
List<Story> stories = extractStories(htmlContent);

// Print the latest stories
for (Story story : stories) {
System.out.println(story.getTitle());
System.out.println(story.getLink());
System.out.println();
}
} catch (IOException e) {
e.printStackTrace();
}
}

private static String fetchWebpage(String url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod("GET");

StringBuilder content = new StringBuilder();
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String inputLine;
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
}

connection.disconnect();
return content.toString();
}

private static List<Story> extractStories(String htmlContent) {
List<Story> stories = new ArrayList<>();

// Here, you need to implement the logic to parse the HTML content and extract the latest stories.
// This involves using basic string processing techniques to locate the titles and links of the stories.
// The example JSON in the assignment can be used as a guide.

// For the sake of this code snippet, let's assume you have extracted the stories into a list of Story objects.
// Replace this with your actual parsing logic.
stories.add(new Story("Amy Schneider’s Jeopardy! Streak Ends at 40 Consecutive Wins and $1.4 Million",
"https://time.com/6142934/amy-schneider-jeopardy-streak-ends/"));
stories.add(new Story("'Writing With Fire' Shines a Light on All-Women News Outlet",
"https://time.com/6142628/writing-with-fire-india-documentary/"));
stories.add(new Story("Moderna Booster May Wane After 6 Months",
"https://time.com/6142852/moderna-booster-wanes-omicron/"));
stories.add(new Story("Pressure Mounts for Biden to Nominate a Black Woman to the Supreme",
"https://time.com/6142743/joe-biden-supreme-court-nominee-black-woman-campaignpromise/"));
stories.add(new Story("The James Webb Space Telescope Is in Position—And Now We Wait",
"https://time.com/6142769/james-webb-space-telescope-reaches-l2/"));
stories.add(new Story("We Urgently Need a New National COVID-19 Response Plan",
"https://time.com/6142718/we-need-new-national-covid-19-response-plan/"));

return stories;
}
}

class Story {
private String title;
private String link;

public Story(String title, String link) {
this.title = title;
this.link = link;
}

public String getTitle() {
return title;
}

public String getLink() {
return link;
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.