2012-10-19 2 views
0

내가 뭘하고 싶은지 : 최고 게시물의 텍스트 제목을 http://reddit.com/r/worldnews에 가져다가 그 텍스트 만있는 웹 페이지로 출력하십시오.특정 부분 또는 웹 사이트의 div를 얻는 방법

결국 나는 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> 

내가 던져해야하는 다른 모든 것들입니까?

+1

스크래핑 방법을 살펴보십시오. http://stackoverflow.com/questions/26947/how-to-implement-a-web-scraper-in-php – Steven

답변

0

당신은 자바에서 file_get_contents 페이지

당신은 URLConnection의 그것을 PHP로 wget을 페이지

을 얻을 수 있었다 수있는 쉘에서 개봉 된 경우

당신이 일단 원하는 언어로 페이지의 텍스트를보고 원하는 내용을 사용하고 원하는 내용대로 수행하십시오.

0

구문 분석을해야 할 것입니다. 그래서 당신이 원하는 패턴을 일치시킵니다. 가장 간단한 것은 str_pos와 같은 것을 사용하여 원하는 요소를 중심으로 요소의 위치를 ​​얻거나 정규 표현식을 사용하는 것입니다. RSS 피드가 있습니까? 그렇다면 그것을 사용해야합니다.

관련 문제