【发布时间】:2012-11-23 17:21:49
【问题描述】:
我有一张这张表,我需要获取表行中第二个 TD 的值。我可以用 PHP 做到这一点,如何做到这一点?
这是我的桌子:
<table class = "jshop cart">
<tr class = "jshop_prod_cart odd">
<td class = "jshop_img_description_center">
<a href = "/shopping/index.php/product/view/210/3690">
<img src = "http://localhost/shopping/components/com_jshopping/files/img_products/noimage.gif" alt = "test" class = "jshop_img" />
</a>
</td>
<td style="text-align:left">
FIRST VALUE I NEED
</td>
<td>
1 ден. </td>
<td>
<input type = "text" name = "quantity[0]" value = "1" class = "inputbox" style = "width: 25px" />
</td>
<td>
1 ден. </td>
<td>
<a href = "/shopping/index.php/cart/delete?number_id=0" onclick="return confirm('Навистина сакате да го отстраните?')"><img src = "http://localhost/shopping/components/com_jshopping/images/remove.png" alt = "Отстрани" title = "Отстрани" /></a>
</td>
</tr>
<tr class = "jshop_prod_cart even">
<td class = "jshop_img_description_center">
<a href = "/shopping/index.php/product/view/169/2876">
<img src = "http://localhost/shopping/components/com_jshopping/files/img_products/thumb_3e28bb073e2ac2ca90345955ead6fc58.JPG" alt = "" class = "jshop_img" />
</a>
</td>
<td style="text-align:left">
SECOND VALUE I NEED
</td>
<td>
140 ден. </td>
<td>
<input type = "text" name = "quantity[1]" value = "1" class = "inputbox" style = "width: 25px" />
</td>
<td>
140 ден. </td>
<td>
<a href = "/shopping/index.php/cart/delete?number_id=1" onclick="return confirm('Навистина сакате да го отстраните?')"><img src = "http://localhost/shopping/components/com_jshopping/images/remove.png" alt = "Отстрани" title = "Отстрани" /></a>
</td>
</tr>
</table>
【问题讨论】:
-
PHP 无法做到这一点。因为数据在客户端,所以需要用到JavaScript。
-
简短的回答是不,你不能。 PHP是服务器端的。它生成 HTML。您不能使用 PHP 在客户端读取网页内容。您需要使用客户端(即 javascript)技术来读取 DOM。除非您的意思是要解析 HTML 服务器端?那就另当别论了。
-
@Diodeus 不一定。 Curl 可用于下载页面,然后使用 XPath 提取所需的数据。
-
是的 - 但这就像用右手抓挠左耳,将手臂放在头顶上方。
标签: php html dom html-table