2012-08-23 4 views
-1

안녕하세요 저는 웹 사이트를 긁어 모으기를 사용하고 있지만 필요하지 않은 정보가 너무 많습니다. 내가 필요로 무엇웹 스크래핑 제거 ID/클래스없이 PHP 링크 첨부 제거

<table id="CompanylistResults"> 
<tbody> 
<tr> 
<tr> 
<td> 
<a target="_blank" rel="nofollow" href="http://www.1800flowers.com">1-800 FLOWERS.COM, Inc.</a> 
</td> 
<td> 
<td style="">$100.55M</td> 
<td style="display:none"></td> 
<td>United States</td> 
<td>1999</td> 
<td style="width:105px">Other Specialty Stores</td> 

는 "1-800 FLOWERS.COM, 주식 회사"입니다 : 여기 내 코드입니다 :

<?php 
require('phpQuery.php'); 
$url = 'http://www.nasdaq.com/screening/companies-by-name.aspx?letter=A'; 
$html = file_get_contents($url); 
$pq = phpQuery::newDocumentHTML($html); 
echo $pq['#CompanylistResults']; 
?> 

그리고 그 결과는 그리고 텍스트에서 "$ 100.55M", 어떻게해야합니까?

+2

이런 종류 긁어 할 필요가 없습니다 수십 API의에서 사용할 수 있습니다. 바로 그 페이지에 링크가 있습니다 : "csv 파일을 제공하는"이 목록을 다운로드하십시오 –

+0

다스 api의 ??? 실제로이 두 텍스트를 사용하여 링크를 만들고 웹 사이트에 표시하고 싶습니다. –

답변

0

이 코드를보십시오 : 금융 정보의

//the url you need to scrape 
$uri = ('http://www.nasdaq.com/screening/companies-by-name.aspx?letter=A'); 
//extracts HTML from the url 
$get = file_get_contents($uri); 

//Finding what you want removed 
$pos1 = strpos($get, "<a target=\"_blank\" rel=\"nofollow\" href=\"http://www.1800flowers.com\">"); 
$pos2 = strpos($get, "</a>", $pos1); 

$pos3 = strpos($get, "<td style=\"\">"); 
$pos4 = strpos($get, "</td>", $pos3); 

//Removing the parts that are not needed 
$text = substr($get,$pos1,$pos2-$pos1); 
$test3 = substr($get,$pos3,$pos4-$pos3); 

//Removing tags from is left after the above code, you should now have only the values that you are looking for 
$text1 = strip_tags($text); 
$text2 = strip tags($text3); 
+0

코드 스 니펫이 무엇을하고 있는지 더 자세히 설명해야합니다. 이렇게하면 질문에 대한 답변을 혼동하지 않고 모두 이해할 수 있습니다. – Mike

+0

오른쪽 ... $ uri 당신이 긁어 내야 할 URL을 넣으십시오. $ – Stefano

+0

맞습니다 ... $ uri에 URL을 넣으십시오. $ get (file_get_contents) url, whit $ pos1 및 $에서 HTML을 추출하십시오. pos2는 $ text와 함께 $ pos3과 $ pos4 사이의 $ pos3과 $ pos4 사이의 코드를 얻습니다. strip_tags()를 사용하면 값을 얻습니다. – Stefano