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
https://forums.phpfreaks.com/topic/273293-simple-html-dom-get-width-value/
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";
   }

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.