I want to retrieve the value of href tag and then navigate to the page and retrieve some other data.
Please find attached a snippet,
<table>
<tr>
<td></td>
<td></td>
<td></td>
<td><a href="http://www.xyz.com" target="abc"></a></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td><a href="http://www.pqr.com" target="mnp"></a></td>
</tr>
</table>
I am currently using loadHTML() to parse the results for <tr> and <td> tags but i am unable to parse the href attribute of <a> tag. How can we get the value of href attribute i.e. http://www.xyz.com in this case?
I want to retrieve the value of href attribute
Moderator: General Moderators
-
priyanka1985
- Forum Newbie
- Posts: 2
- Joined: Thu Feb 25, 2010 9:43 am
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: I want to retrieve the value of href attribute
What did you try?
getElementsByTagName()
getAttribute()
getElementsByTagName()
getAttribute()
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
priyanka1985
- Forum Newbie
- Posts: 2
- Joined: Thu Feb 25, 2010 9:43 am
Re: I want to retrieve the value of href attribute
Hey, I am currently using the following code for parsing,
$tables = $dom->getElementsByTagName("table");
$rows = $tables->item(1)->getElementsByTagName("tr");
foreach($rows as $row){
$cols = $row->getElementsByTagName("td");
echo @$cols->item(0)->nodeValue;
echo @$cols->item(1)->nodeValue;
echo @$cols->item(2)->nodeValue;
echo @$cols->item(3)->nodeValue;
echo "<br />";
}
}
But i am not sure how to incorporate the code for <a> tag. Can you please help?
$tables = $dom->getElementsByTagName("table");
$rows = $tables->item(1)->getElementsByTagName("tr");
foreach($rows as $row){
$cols = $row->getElementsByTagName("td");
echo @$cols->item(0)->nodeValue;
echo @$cols->item(1)->nodeValue;
echo @$cols->item(2)->nodeValue;
echo @$cols->item(3)->nodeValue;
echo "<br />";
}
}
But i am not sure how to incorporate the code for <a> tag. Can you please help?
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: I want to retrieve the value of href attribute
Not trying to be rude, but if you use this:
$tables = $dom->getElementsByTagName("table"); to get <table> tags, what do you think you would change to get <a> tags?
$tables = $dom->getElementsByTagName("table"); to get <table> tags, what do you think you would change to get <a> tags?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.