我想做的:从http://reddit.com/r/worldnews的顶部帖子中获取文本标题并将其输出到我的网页上,该网页上只有该文本。
最后,我想从我使用 AppleScript cURL 制作的网页中获取文本并将其输出。
我正在制作一个脚本,当我单击按钮时,它会告诉我最上面的帖子。
编辑如果您能想到任何方式,我想做同样的事情,但对于 Facebook 通知。
编辑我让 PHP 抓取该站点并在此处输出:http: //colejohnsoncreative.com/personal/ai/worldnews.php这是我正在使用的代码:
<?php
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('http://www.reddit.com/r/worldnews');
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
// Another example, let's get a web page into a string. See also file_get_contents().
$html = implode('', file('http://www.example.com/'));
// Using the optional flags parameter since PHP 5
$trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
?>
所以我得到了网站的所有代码输出,但我需要的项目是
<a class="title " href="http://www.dailymail.co.uk/news/article-2219477/Cannabis-factory-couple-gave-400-000-drug-dealing-fortune-poor-Kenyans-jailed-years.html" >British couple who spent most of the money they made from canabis growing on paying for life changing operations and schooling for people in a poor Kenyan village gets sent to prison for 3 years.</a>
以及我需要扔掉的所有其他东西,我该怎么做?