A recent project is to implement a simple vertical search engine, in the crawler, to analyze all the URLs on the page. But some URLs take the form of a relative link address.
For example: http://blog.csdn.net/lizhihaoweiwei/article/details/17839481 This page has a link called 34342, then the real address of this link is:
http://blog.csdn.net/lizhihaoweiwei/article/details/34342. So I'm going to write a function to complete the conversion. Taking into account the following circumstances:
The same layer./
Root Tier/
May be the current layer may also be a stand-alone URL abc
Upper layer (previous layer above) Wait
Write a hard function to deal with these situations, to consider the fault tolerance of processing, writing a bit complicated. After the realization of a little complacent mood.
Finally accidentally found that the URL class has several construction methods, one of which is the URL (url,string), the first look at the construction method to feel a little strange, what is the initial parameter URL meaning. Again, this may be a reference to the URL, the latter may be relative to the link address. The final validation is true. It's not a good deal to waste a couple of hours in this place.
Summary: Write code to have jumped out of the mind, a glance at the small mountains of the feeling. Do not worry about solving problems, but to figure out how to solve them. For example, this is to deal with the URL-related, you should first see whether the URL provides this function.