PHP information collection can't get content?

Source: Internet
Author: User
PHP Curl Information Acquisition simulation Browser collection

Today suddenly want to collect something, just start can, all normal, but after a period of time on what also not to collect, do not know where the problem is, code as follows, ask you?
function GetContent ($url) {
$url = Trim ($url);
$content = ";
if (extension_loaded (' curl ')) {
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, curlopt_followlocation, 1);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, Curlopt_httpheader,array (
' ACCEPT-LANGUAGE:ZH-CN ',
' Connection:keep-alive ',
' Cache-control:no-cache '
));
$user _agent = "mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ";
curl_setopt ($ch, curlopt_useragent, $user _agent);
$content = curl_exec ($ch);
Curl_close ($ch);
} else {
$content = file_get_contents ($url);
}
Return trim ($content);

}//end func getcontent ();


Reply to discussion (solution)

What's the URL you're collecting?

What's the URL you're collecting?
For example, this address: http://movie.douban.com/subject/10604486/?from=playing

You're not allowed to collect it, are you?

If you can try to take down the contents of this address: http://www.tianya.cn/43064769, originally only want some funny content, and later even the page will not open

You're not allowed to collect it, are you?
Yes, maybe I collected too fast, I feel a little sorry for them. I use the browser can open normally, but the acquisition is not, now there is any way to continue to collect it?

In fact, I feel that my program is not perfect, otherwise it will not be browser can and program can not, to help improve my program, I really do not know where is not perfect, please do not hesitate to enlighten!!!

There's nothing perfect here, maybe you're calling too often. I don't know how you call it.

There's nothing perfect here, maybe you're calling too often. I don't know how you call it.
I am directly that address put in call of Ah, also not too often, if too often what will happen?

I am using the loop call, the middle without a pause, loop less than 100 times. Now I've got a break in the middle of the loop, but I can't keep picking now.

I don't know, but it's definitely going to put a lot of pressure on the server.

Apparently it's been sealed off, and in general, we'll be able to continue sampling in two days.

You first calculate how long the middle is going to be blocked and then set the stop time. Use Usleep or sleep control. or with proxy IP bar, I am also in the collection, the sense of pause collection efficiency will be much lower.

The browser can be opened to indicate that there is no closure, a catch check does a complete simulation of a certain line

The browser can be opened to indicate that there is no closure, a catch check does a complete simulation of a certain line
This is not necessarily, I collected a few days ago Baidu page, the browser can open normally, but is not collected data, the other side estimate whether it is simulated crawl.

  • 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.