2012-01-07 68 views
-1

我有一个问题从HTML表中分析单词。我需要单独从其他内容(“引理”列)的话来说:从HTML表中分离单词并将它们保存在txt文件中

页面俄罗斯的原始版本 - http://hsu.su/st2

英语(GOOGLETRANSLATE) - http://hsu.su/155

我听说PHP简单的HTML DOM解析器http://simplehtmldom.sourceforge.net/但我无法弄清楚如何解决这个问题与他。

+0

看到http://stackoverflow.com/questions/3577641/best-methods-to-parse-html – Gordon 2012-01-07 14:58:13

回答

1
<?php 
    include_once('simplehtmldom/simple_html_dom.php'); 
    $html = file_get_html('http://dict.ruslang.ru/freq.php?act=show&dic=freq_news_comp&title=%D1%EB%EE%E2%E0%F0%FC%20%E7%ED%E0%F7%E8%EC%EE%E9%20%E3%E0%E7%E5%F2%ED%EE-%ED%EE%E2%EE%F1%F2%ED%EE%E9%20%EB%E5%EA%F1%E8%EA%E8'); 

    $myFile = "file.txt"; 
    $fh = fopen($myFile, 'w') or die("can't open file"); 


    $table=$html->find('table',1); 
    foreach($table->find('td') as $td) 
    fwrite($fh, $td->plaintext); 

    fclose($fh); 
    ?> 

下载simplehtmldom ..

复制它在同一文件夹

确保代码inluded路径指向正确的类

make文件。 txt文件在同一文件夹中。

并运行代码...

你有

'&nbsp;' 

额外的,你可以从PHP字符串函数删除..

+0

** Rajat SinghalI **真诚地感谢您的宝贵帮助! – user1103744 2012-01-08 11:49:47

+0

不客气.. :) – 2012-01-08 12:34:02

-1

查看PHP函数strip_tags()。从您提供的相同的链接

+0

'strip_tags'将删除标签。这将使OP仍然面临着如何从现在非结构化文本中获取数据的问题。 – Gordon 2012-01-07 15:31:41

相关问题