PHP crawls webpage code and image paths

Source: Internet
Author: User
PHP crawls web page code. I am using php code to capture the URL code first. , Ob_start (); & nbsp; $ ch = curl_init (); & nbsp; curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, cu php captures webpage code, image path problems
I will first use php code to capture the code for connecting to the URL. ,
Ob_start ();
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
$ Retrievedhtml = curl_exec ($ ch );
Ob_end_clean ();
Curl_close ($ ch );

Now there is a situation, for example, the Web site is http://www.aaa.com/bq/
Then the link address of the image on the webpage is

At this time, it is reasonable to say that the complete URL of the image should be http://www.aaa.com/bq/cq/a.jpg
However, after the conversion, I found that the image cannot be displayed, and then I found that the image path is actually
Http://www.aaa.com/cq/a.jpg

How can I explain this and determine the path?

------ Solution --------------------
Generally, it's not/bq/cq/a.jpg.
Take a good look at this path:

/To the root
Picture path is http://www.aaa.com/cq/a.jpg
You can test a few more images and immediately understand that there is no dot in front of/. jump to the root node. if there is a dot, you can skip to the current path.
------ Solution --------------------
The domain name is relative to the domain name.
The url is relative to the url.

Don't you write your own website?
Just capture others?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.