jccyber
asked on
PHP Sracper
Hello Experts,
I am trying to scrape the content of a page and replacing some of the content by my own content! I am also trying to keep the look and feel of the page intact.
I have added 2 tags to separate the bottom from the top
<!--top-end-->
<!--bottom-start-->
How!!!
I am trying to scrape the content of a page and replacing some of the content by my own content! I am also trying to keep the look and feel of the page intact.
I have added 2 tags to separate the bottom from the top
<!--top-end-->
<!--bottom-start-->
How!!!
What part do you want to replace ? between those two ? preg_replace would be the way to go.
ASKER
Whatever is in between
<!--top-end-->
<!--bottom-start-->
<!--top-end-->
<!--bottom-start-->
Try this:
<?php
$somehtml = "<html><head></head><body> <!--top-en d-->some text<!--bottom-start--></b ody></html >";
$somehtml = preg_replace("/<!--top-end -->(.*?)<! --bottom-s tart-->/im s", "mytext", $somehtml);
echo $somehtml;
?>
<?php
$somehtml = "<html><head></head><body>
$somehtml = preg_replace("/<!--top-end
echo $somehtml;
?>
ASKER
I am currently using this code to get the page
$url="http://mydomain/page.html";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
$file=curl_exec ($ch) or die(curl_error());
curl_close ($ch);
echo $file;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you want to post the actual URL of the page you want to scrape, we might be able to provide more concrete answers. But that said, please be sure that you have permission to access the page in an automated manner and that you have copyright for the information you are using. Many sites do not allow web scraping and explicitly deny this use case in their terms of service. Also, many sites that want to allow automated access to the underlying data model will offer an API. Just a thought, ~Ray
ASKER
This is it.
Thank you
Thank you