user19153785
user19153785

Reputation:

PHP cURL delay the execution for few seconds

I'm trying to get the Bing search count result using PHP cURL.

I tried cURL but the response is not returning any result. It is returning only the header and footer of the Bing search page.

My code:

$url = "https://www.bing.com/search?q=site:mysite.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
sleep(10);
$response = curl_exec($ch);
curl_close($ch);

Output HTML: enter image description here

Then I tried with Python with sleep.

url = "https://www.bing.com/search?q=site:mysite.com";
browser.get(url)
time.sleep(1)
print(browser.page_source)  # results

And this returned the HTML with Bing search result count.

    ......
    <span class="sb_count" data-bm="4">465 results</span>
    .....

Similar to Python how can I sleep PHP cURL execution in between for few seconds and get the search result.

Any help would be appreciated. Thanks in advance.

Upvotes: 0

Views: 798

Answers (1)

Martin Zeitler
Martin Zeitler

Reputation: 76589

This approach is a) not feasible and b) questionable.
There's a Bing Search API, which appears more likely.

Upvotes: 1

Related Questions