2

When trying to parse html using simple html parser, I get no response. Here is the code:

$html = new simple_html_dom();  
$html->file_get_html('http://thepiratebay.se/search/1080p/0/7/207');

$html returns nothing. However, when I'm doing the same thing using this url, http://thepiratebay.se/browse/207/0/7, I get a normal response.

I don't really understand why since the url works perfectly.

A var_dump on $html returns a bool (false).

I have php 5.3.1 and allow_url_fopen is on in php.ini

1
  • I'm sorry, but I did genuinely laugh at this question... Do you get any errors of any sort? Commented Mar 26, 2013 at 12:18

1 Answer 1

4

Use cURL and set a user-agent. Apparently thepriatebay.se does not to respond to requests without a user-agent.

This grabs the user-agent of your browser and sends it to the target.

curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

To request a web page through cURL, use the following:

// Start a cURL resource
$ch = curl_init();
// Set options for the cURL
curl_setopt($ch, CURLOPT_URL, 'http://thepiratebay.se/search/1080p/0/7/207'); // target
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // provide a user-agent
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow any redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the result
// Execute the cURL fetch
$result = curl_exec($ch);
// Close the resource
curl_close($ch);
// Output the results
echo $result;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.