Jump to content

Get EXACT value (including HTML elements) of textarea with XPATH


inVINCEable

Recommended Posts

$target_url = "****"; 
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';

// make the cURL request to $target_url
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html= curl_exec($ch);
if (!$html) {
echo "
cURL error number:" .curl_errno($ch);
echo "
cURL error:" . curl_error($ch);
exit;
}




// parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);

// grab all the on the page
$xpath = new DOMXPath($dom);

$xml = simplexml_import_dom($dom);


$names = $xml->xpath('//textarea');
    foreach($names as $name) {
        echo "$name<br />";
    }

 

Ok, everything works perfectly except one thing. When I view my page (here listed as *** to remain private) in the textarea element I get my words that I am scraping AND the html elements that are to be displayed  (not the html elements for the page formatting, but HTML elements to actually be viewed so users can copy and paste the code). This works fine when viewing it, but when using the above code to scrape the content, only the words show, not the actual HTML elements that appear in the textarea. Is there a workaround for this? I'm assuming XPATH thinks they are elements of the actual page.

 

Any help is GREATLY appreciated.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.