如何提取部分HTML页面 [英] how to extract part of HTML page

查看:66
本文介绍了如何提取部分HTML页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在尝试编写一个PHP脚本,使用cURL连接到银行的货币

转换页面那部分工作正常。问题是我用一个包含大量我不需要的信息的页面结束了
。使用

PHP函数strip_tags我已经结束了下面的文本和

剩余的HTML代码,我想提取以>开头的行。 < TABLE

BORDER =" 1" WIDTH =" 315">"直至结束< / TABLEtag。我怎么做这个

使用PHP?我尝试使用preg_match之类的,但我的正则表达式技能是非常糟糕的。不太确定从哪里开始。有人可以提供给我

有一些指示吗?

========================= ========================= ========================= ==============

< TABLE BORDER =" 0" WIDTH =" 600"

< tr>

< td width =" 148">< / td>

< td width =" 448">一些文字一些文字一些文字一些文字一些文字< / td>

< / tr>

< / TABLE>


< TABLE BORDER =" 0" WIDTH =" 600"

< TR>< TD VALIGN =" top" WIDTH =" 148>>

< / TD>

< TD WIDTH =" 448" VALIGN =" top">

< TABLE BORDER =" 0" WIDTH =" 448>>

< TR>< TD>

有些文字有些文字有些文字有些文字有些文字有些文字有些文字有些

发短信一些文字。

一些文字一些文字一些文字一些文字一些文字

< / TD>< / TR>

< TR>< TD>

< TABLE BORDER =" 1" WIDTH =" 315" < -----从这里提取




< TR>< TD>

一些文字有些文字一些文字一些文字一些

text

< / TD>

< TD ALIGN =" right">

一些文字一些文字一些文字一些文字一些

文字

< / TD>< / TR>

< TR>< TD>

有些文字有些文字有些文字有些文字有些

text

< / TD>


< TD ALIGN =" right">

有些文字有些文字有些文字有些文字有些

text

< / TD>< / TR>

< TR>< TD>

有些文字有些文字有些文字有些文字有些

text

< / TD>

< TD ALIGN =" right">

一些文字有些文字有些文字一些文字一些

text

< / TD>< / TR>

< / TABLE>

< ---------到这里

< / TD>< / TR>

< TR ><>>

a {

颜色:蓝色;

}

有些文字有些文字有些文字一些文字一些文字

一些文字一些文字一些文字一些文字一些文字一些文字

一些文字一些文字一些文字一些文字

一些文字一些文字一些文字一些文字一些文字一些文字

一些文字一些文字一些文字一些文字

< / TD>< / TR>

< TR>< TD>

一些文字一些文字一些文字一些文字一些文字

一些文字一些文字一些文字一些文字一些文字一些文字

一些文字一些文字一些文字一些文字一些文字一些

< / TD>< / TR>

< / TABLE>

< / TD>< / TR>

< / TABLE>

< br>

= ================================================= = ======================================

谢谢

Eric

解决方案

2008年9月16日星期二21 :42:20 + 1000,Ecka写道:


我想提取以< TABLE开头

的行BORDER =" 1 QUOT; WIDTH =" 315">"直至结束< / TABLEtag。



使用DOMDocument :: loadHTML(),您只需在

HTML上执行XPath查询。

另一种方法是将HTML分成行,循环遍历行和

将< tableand< / tablein之间的所有行放在一个字符串中:


lines = explode(''\ n'',


text);

foreach(

Hi everyone,

I''m trying to write a PHP script that connects to a bank''s currency
convertor page using cURL and that part works fine. The issue is that I end
up with a page that includes a lot of information that I don''t need. Using
the PHP function strip_tags I''ve ended with the text below and from the
remaining HTML code, I''d like to extract the lines starting with "<TABLE
BORDER="1" WIDTH="315">" up to its closing </TABLEtag. How do I do this
using PHP? I tried using preg_match and the like but my regex skills are
pretty bad. Not too sure where to start. Could someone please provide me
with some pointers?
================================================== =======================================
<TABLE BORDER="0" WIDTH="600">
<tr>
<td width="148"></td>
<td width="448">some text some text some text some text some text</td>
</tr>
</TABLE>

<TABLE BORDER="0" WIDTH="600">
<TR><TD VALIGN="top" WIDTH="148">
</TD>
<TD WIDTH="448" VALIGN="top">
<TABLE BORDER="0" WIDTH="448">
<TR><TD>
some text some text some text some text some text some text some text some
text some text some text.
some text some text some text some text some text
</TD></TR>
<TR><TD>
<TABLE BORDER="1" WIDTH="315" <----- extract
from here

<TR><TD>
some text some text some text some text some
text
</TD>
<TD ALIGN="right">
some text some text some text some text some
text
</TD></TR>
<TR><TD>
some text some text some text some text some
text
</TD>

<TD ALIGN="right">
some text some text some text some text some
text
</TD></TR>
<TR><TD>
some text some text some text some text some
text
</TD>
<TD ALIGN="right">
some text some text some text some text some
text
</TD></TR>
</TABLE>
<--------- to here
</TD></TR>
<TR><TD>
a {
color:blue;
}
some text some text some text some text some text
some text some text some text some text some text some text
some text some text some text some text
some text some text some text some text some text some text
some text some text some text some text
</TD></TR>
<TR><TD>
some text some text some text some text some text
some text some text some text some text some text some text
some text some text some text some text some text some
</TD></TR>
</TABLE>
</TD></TR>
</TABLE>
<br>
================================================== =======================================
Thanks
Eric

解决方案

On Tue, 16 Sep 2008 21:42:20 +1000, Ecka wrote:

I''d like to extract the lines starting
with "<TABLE BORDER="1" WIDTH="315">" up to its closing </TABLEtag.

With DOMDocument::loadHTML(), you can simply do an XPath query on the
HTML.

An alternative is to split the HTML in lines, loop through the lines and
put all the lines between <tableand </tablein a string:


lines = explode(''\n'',


text);
foreach (


这篇关于如何提取部分HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆