Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5929867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:28:51+00:00 2026-05-22T14:28:51+00:00

im writing a simple webcrawler. the problem is, with the link extraction. i uses

  • 0

im writing a simple webcrawler. the problem is, with the link extraction.

i uses the cpp-netlib with boost. here a few lines of my CLink Class.

    CLink::CLink(const CLink& father, const std::string& relUrl )
    {
     uri = relUrl;
     boost::network::uri::uri instance(relUrl);
     boost::network::uri::uri instanceFather(father.uri);

     if ( (valid = boost::network::uri::is_valid(instance)) == 1)
      {
       scheme    = boost::network::uri::scheme(instance);
       user_info = boost::network::uri::user_info(instance);
       host      = boost::network::uri::host(instance);
       port      = boost::network::uri::port(instance);
       path      = boost::network::uri::path(instance);
       query     = boost::network::uri::query(instance);
       fragment  = boost::network::uri::fragment(instance);

       uri  = scheme;
       uri += "://";
       uri += host;
       uri += path;

      }
     else
      {
       if ( (valid = boost::network::uri::is_valid(instanceFather)) == 1)
        {

         scheme    = boost::network::uri::scheme(instanceFather);
         user_info = boost::network::uri::user_info(instanceFather);
         host      = boost::network::uri::host(instanceFather);
         port      = boost::network::uri::port(instanceFather);
         path      = boost::network::uri::path(instance);
         query     = boost::network::uri::query(instance);
         fragment  = boost::network::uri::fragment(instance);

         uri  = scheme;
         uri += "://";
         uri += host;
         uri += path;

        }
      }
    };

    CLink::CLink( const std::string& _url )
    {

     uri = _url; 
     boost::network::uri::uri instance(_url);
      if ( (valid = boost::network::uri::is_valid(instance) ) == 1)
       {
       scheme    = boost::network::uri::scheme(instance);
       user_info = boost::network::uri::user_info(instance);
       host      = boost::network::uri::host(instance);
       port      = boost::network::uri::port(instance);
       path      = boost::network::uri::path(instance);
       query     = boost::network::uri::query(instance);
       fragment  = boost::network::uri::fragment(instance);


       uri  = scheme;
       uri += "://";
       uri += host;
       uri += path;

         }
        else
      std::cout << "err " << std::endl;
    };

the links from the webpage i took with the htmlcxx lib. i took the HTML::Node and normalize them wih the boost filesystem.

 if ( url.find("http://") == std::string::npos)
  {
   std::string path = link.get_path() + url;   
   url =  link.get_host() + path;

   boost::filesystem::path result;
   boost::filesystem::path p(url);
   for(boost::filesystem::path::iterator it=p.begin(); it!=p.end(); ++it)
    {
     if(*it == "..")
      {
       if(boost::filesystem::is_symlink(result) )
    result /= *it;
       else if(result.filename() == "..")
    result /= *it;
       else
    result = result.parent_path();
      }
     else if(*it == ".")
      {
       // Ignore
      }
     else
      {
       // Just cat other path entries
       result /= *it;
      }
    }

   url = "http://" + result.string();
  }

 return ret;

Now the problem is.

i try to fetch http://www.wikipedia.de/ and i get the urls like

properties
http://wikimedia.de/wiki/Vereinszeitung
… …

and on the site http://wikimedia.de/wiki/Vereinszeitung there is a link like /wiki/vereinsatzung

so often i get links like

http://wikimedia.de/wiki/Vereinszeitung/wiki/Freies_Wissen

does someone have a idee?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:28:52+00:00Added an answer on May 22, 2026 at 2:28 pm

    You need to have a special case for absolute links (those that start with /).

    If the href starts with /, then the resulting link should be (using the terms from The URI template which come from the RFC):

    [scheme]://[authority][what you got in href]
    

    What you are currently constructing is:

    [scheme]://[authority][path][what you got in href]
    

    So you’re duplicating the path information.

    So if link.get_path() starts with /, you should simply change:

    std::string path = link.get_path() + url;   
    url =  link.get_host() + path; // this is incorrect btw, missing the [port]
    

    to

    url =  link.get_host() + ":" + link.get_port() + url;
    

    It would probably be cleaner to do the path normalization on the path only, not on the URL (i.e. add host:port after normalizing the path).

    [And I think your code will fail if it encounters an https link.]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple OpenGL application that uses GLUT . I don't want to
I'm learning Rails by writing simple TODO tasks aplication. Two models are: class List
I was writing a simple PHP page and a few foreach loops were used.
I'm writing simple chat program in Ada, and I'm having problem with chat window
I am writing simple blog with CodeIgniter and DataMapper and I have problem with
Writing a simple example from Odersky's book resulted in the following problem: // AbstractElement.scala
I've been recently writing simple game in C++ with SFML. Here's my question: In
Hello I'm writing simple j2me calculator. using GameCanvas class as a basis of my
I'm writing a simple custom function in Facelets with a sample method. The problem
I'm writing a simple web crawler in Ruby and I need to fetch all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.