本文介绍了如何使用 CURL 解析 html 文件中的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 CURL 解析 XHTML 内容.如何在 标签之间废弃交易号、重量、高度、宽度.如何使用 CURL 仅从该 HTML 文档中删除内容并将其作为数组获取?
I want to parse an XHTML content using CURL. How to scrap transaction number, weight, height, Width between <table>
tags. How to scrap only the contents from this HTML document and get it as array using CURL?
transactions.php
<table border=0 cellspacing=0 width=100%>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td width="30%" class="Mellemrubrikker">Transaction Number::</td>
<td width="70%">24752734576547IN</td>
</tr>
<tr>
<td width="30%" class="Mellemrubrikker">Weight:</td>
<td width="70%">0.85 kg</td>
</tr>
<tr>
<td width="30%" class="Mellemrubrikker">Length:</td>
<td width="70%">543 mm.</td>
</tr>
<tr>
<td width="30%" class="Mellemrubrikker">Height:</td>
<td width="70%">156 mm.</td>
</tr>
<tr>
<td width="30%" class="Mellemrubrikker">Width:</td>
<td width="70%">61 mm.</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
index.php
<?php
$url = "http://localhost/htmlparse/transactions.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
//print_r($output);
echo $output;
?>
此代码从 transactions.php 获取整个 html 内容.如何获取之间的数据作为数组值?
This code gets whole html content from transactions.php . How to get data between <table>
as an array value ?
推荐答案
从 http://simplehtmldom 尝试简单的 html dom.sourceforge.net/
如果您不介意使用 python 或 perl,您可以使用 beautifulsoup 或 WWW-Mechanize
If you don't mind to use python or perl you can use beautifulsoup or WWW-Mechanize
这篇关于如何使用 CURL 解析 html 文件中的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文