The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 23, 2019, 10:35:49 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: PHP and Domxpath  (Read 1935 times)
LondonSEO
Rookie
**
Offline Offline

Posts: 15


View Profile
« on: December 06, 2007, 03:50:55 PM »

Hi,

I'm working on a new scraping script, as simple as detect if the site that I'm querying has a SITEMAP or NOT so I was playing with some domxpath to get the html and play with it, but I think that am I limited to the attributes?

Code:
...some more code
$dom = new DOMDocument();
@$dom->loadHTML($myhtml);

$xpath = new DOMXPath($dom);

$hrefs = $xpath->evaluate("/html/body//a");


for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);

$url = $href->getAttribute('href');
//$alt = $href->getAttribute('alt');
//$target = $href->getAttribute('target');

echo "<br />Hey take a look: $url";

.... close

Any ideas how can I get domxpath to let me know if a site has a string (...anything...SITEMAP...anything)

Thank you

J.


Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: December 09, 2007, 03:35:33 PM »

Why use the DOM to get that info?
Just preg_match for the string you're looking for, then load it into the DOM if you find it has what you want.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!