Jump to content

Simple HTML Dom... get width value


acctman

Recommended Posts

Hi i'm using Simple HTML Dom to scrap a site page. I'm trying to grab the width value for each img src. Below is the html and php i've been using so far.

 


<table>
<tr>
<th colspan="4">
<font size="3" color="#a74165">Interest Levels</font>
</th>
</tr>
<tr>
<td nowrap>
<font size="2">MobileT</font>
</td>
<td><img src="http://pictures.domain.com/images/7.gif" alt="1 on a scale of 0-4" border="0" height="15" width="9">
</td>
<td>    
</td>
<td nowrap>
<font size="2">MobileC</font>
</td>
<td>
<img src="http://pictures.domain.com/images/7.gif" alt="3 on a scale of 0-4" border="0" height="15" width="27">
</td>
</tr>
<tr>
<td nowrap>
<font size="2">Moderate</font>
</td>
<td><img src="http://pictures.domain.com/images/7.gif" alt="3 on a scale of 0-4" border="0" height="15" width="27">
</td>
<td>    
</td>
<td nowrap>
<font size="2">Males</font>
</td>
<td>
</td>
</tr>
<tr>
<td nowrap>
<font size="2">Wild</font>
</td>
<td><img src="http://pictures.domain.com/images/7.gif" alt="3 on a scale of 0-4" border="0" height="15" width="27">
</td>
<td>    
</td>
<td nowrap>
<font size="2">Females</font>
</td>
<td>
<img src="http://pictures.domain.com/images/7.gif" alt="4 on a scale of 0-4" border="0" height="15" width="36">
</td>
</tr>
</table>

 

 

 


include('simple_html_dom.php');

$html = new simple_html_dom();   
$html = file_get_html('http://dev.domain.com/');

$element = $html->find("td font[size=3]", 0);  
echo $element-> plaintext . '<br>';

$element = $html->find("font", 7);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[color=red]", 0);  
echo $element-> plaintext . '<br>';

$element = $html->find("font", 3);  
echo $element-> plaintext . '<br>';

# city state country
$element = $html->find("font[size=2]", 3);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=2]", 10);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=2]", 11);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=2]", 12);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=-1]", 0);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=-1]", 1);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=-1]", 2);  
echo $element-> plaintext . '<br>';

$element = $html->find("font[size=-1]", 3);  
echo $element-> plaintext . '<br>';

$html->clear();

Link to comment
Share on other sites

According to the Sourceforge Code site:

 

$element = $html->find("font[size=-1]", 3);
echo "Width is: " . $element->width . '<br />';  

 

 

I'm trying to check if there is and image after the <td> tag, and if there is grab the width value. the method i'm using below is not working

 

   $element = $html->find("td", 23);
   if ($element->innertext != null) {
       $element = $html->find("td img[src=http://pictures.domain.com/images/7.gif]");
       echo $element->width . '<br />';        
   } else {
      echo "empty";
   }

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.