Extract URLs from search engine results

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nikkhah
    New Member
    • Apr 2010
    • 12

    #1

    Extract URLs from search engine results

    I want to write a program in java that it can parse search engine results and save URLs and titles in a file, but I don't know how can I do this?
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    You probably want to look up HTTPRequest and Regular Expressions.

    eg something like:
    <a href=".*{url}"> .*{title}</a>

    Comment

    • Nikkhah
      New Member
      • Apr 2010
      • 12

      #3
      Originally posted by jkmyoung
      You probably want to look up HTTPRequest and Regular Expressions.

      eg something like:
      <a href=".*{url}"> .*{title}</a>
      Do you know what instructions do I use?

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        ? What task are you specifically referring to?

        If you haven't already, break your problem into steps. It's easier to help with one step at a time then all of them at once.

        Comment

        • Nikkhah
          New Member
          • Apr 2010
          • 12

          #5
          Originally posted by jkmyoung
          ? What task are you specifically referring to?

          If you haven't already, break your problem into steps. It's easier to help with one step at a time then all of them at once.
          I want to connect to google and save URLs. what do I do?

          Comment

          • Nikkhah
            New Member
            • Apr 2010
            • 12

            #6
            I find a sample code that extract links from an html page. now how can I save html source of search results?

            Comment

            • jkmyoung
              Recognized Expert Top Contributor
              • Mar 2006
              • 2057

              #7
              Here's a quick example from Sun's website:

              Code:
              	public static void main(String[] args) throws Exception {
              		URL url = new URL("http://www.google.com/");
              		URLConnection urlc = url .openConnection();
              		BufferedReader in = new BufferedReader(
              				new InputStreamReader(
              						urlc.getInputStream()));
              		String inputLine;
              
              		while ((inputLine = in.readLine()) != null) 
              			System.out.println(inputLine);
              		in.close();
              	}
              It's pretty easy to find with google.

              Try modifying it to meet your needs, and come back if you have a problem.

              Comment

              Working...