1

我想用 php (file_get_contents?) 阅读一个网站,该网站用 <span style='display:none;'> 隐藏。

4个例子:

  1. U<span style='display:none;'>wsebv</span><u></u>rfahr
  2. Z<span style='display:none;'>e<i></i>i<span></span>nhv</span><b></b>öhrdorf
  3. B<i></i>a<i></i>b<span></span>e<i></i>n<span style='display:none;'>einhv</span>< u></u>伯格
  4. K<span style='display:none;'>s<i></i>d<span style='display:none;'>d<span style='display:none;'>b<span style=' display:none;'>n<span style='display:none;'>v<i></i>b<span style='display:none;'>h<i></i>gawe</span ><u></u>aoi</span><b></b>hvws</span><b></b>aoir</span><b></b>asud</span>< b></b>asu</span><b></b>irchdorf/Kr.

结果应该是:

  1. 乌尔法尔
  2. 佐尔多夫
  3. 巴本贝格
  4. 基希多夫/Kr.

解决问题的两种可能方法(但我不知道如何实现它们):
A)删除所有跨度标签及其内容
B)以编程方式只读 VISIBLE 内容

非常感谢您的帮助!!!

4

2 回答 2

1

http://sourceforge.net/projects/simplehtmldom/files/latest/download?source=files

include('simple_html_dom.php');

$html = file_get_html('http://www.fussballoesterreich.at/netzwerk/datenservice/379402779304830775_O~733830065019629299~744933674800963515~0~1.htm');

$i = 1;
foreach($html->find('.mannschaft a') as $e)
{
    $x = html_entity_decode($e->innertext, ENT_QUOTES, 'UTF-8');
    $x = preg_replace('#<(.*)>#', '', $x);
    echo $i, '. ', $x, '<br />';
    $i++;
}

结果:

1. Garsten
2. S. Valent.ASK
3. Bumgartenberg
4. Neuhofen/Krems
5. Admira
6. Asten
7. Enns
8. Pasching 1b
9. S. Florian 1b
10. SValentin SC
11. Hörsching
12. S Ulrich
13. Wdischgarsten
14. Doppl-Hart

我在这里的工作已经完成。

于 2012-03-15T21:23:34.173 回答
0

应用样式这一事实没有任何区别。对于 PHP,它只是一堆文本。

尝试:

<?php
$url = 'http://....';  // URL you're scraping.
$html = file_get_contents($url);
$text = strip_tags($html);
echo "<PRE>$text</PRE>";
于 2012-03-15T20:09:39.550 回答