How to pick up portions of texo inside a site using Curl

Asked

Viewed 429 times

-1

I have this example with "file_get_contents"

How it would be done using Curl?

<?php
$url = 'http://www.exemplo.com/exemplo.php';
$dadosSite = file_get_contents($url);

$var1 = explode('Da linha 1 até',$dadosSite);
$var2 = explode("Linha 25",$var1[1]);

print $var2[0];
?>
  • You’re not picking up a chunk of the url in your code, you’re picking up a chunk of the site’s content using the explode, your question should be: how do I pick up the chunk from a site using Curl, not?

  • Yes exactly, I’ll change the title

1 answer

1


Friend what you want to do is called Web Scraping, below follows an example with Curl.

$curl = curl_init('www.pudim.com.br');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$page = curl_exec($curl);
$pattern = '#mailto:(.*?)"#';
preg_match($pattern,$page,$resultado);
echo $resultado[0];

In this little piece of code I’m going to get the email from the most famous page on the web. You can test the code above in this website;

  • Thanks friend, exactly what I was looking for

Browser other questions tagged

You are not signed in. Login or sign up in order to post.