natasha_thomas Posted December 5, 2010 Share Posted December 5, 2010 Geek Friends, I have list of URLs in an array called '$domains' 1- I want to run through each and every element of $domains in an API call. API: http://lightapi.majesticseo.com/api_command.php?app_api_key=API_KEY&cmd=GetIndexItemInfo&items=1&item0=http://www.majesticseo.com (Note: In this API "http://www.majesticseo.com" will be replaced with each element of $domain array in a loop) 2- The resulting output is XML: <?xml version="1.0" encoding="utf-8"?> <Result Code="OK" ErrorMessage="" FullError=""> <GlobalVars IndexBuildDate="17/04/2010 16:43:46" MostRecentBackLinkDate="2010-03-25"/> <DataTables Count="1"> <DataTable Name="Results" RowsCount="1" Headers="ItemNum|Item|ResultCode|Status|ExtBackLinks|RefDomains|AnalysisResUnitsCost|ACRank|ItemType|IndexedURLs|GetTopBackLinksAnalysisResUnitsCost|RefIPs|RefSubNets|RefDomainsEDU|ExtBackLinksEDU|RefDomainsGOV|ExtBackLinksGOV|RefDomainsEDU_Exact|ExtBackLinksEDU_Exact|RefDomainsGOV_Exact|ExtBackLinksGOV_Exact"> <Row>0|majesticseo.com|OK|Found|28381|1229|28381|-1|1|4774|28381|1074|954|1|5|0|0|0|0|0|0</Row> </DataTable> </DataTables> </Result> I want to extract the below Elements out of this XML Output for each element of $domains in loop: ACRank ExtBackLinks RefDomains AnalysisResUnitsCost RefIPs RefSubNets RefDomainsEDU ExtBackLinksEDU RefDomainsGOV ExtBackLinksGOV RefDomainsEDU_Exact ExtBackLinksEDU_Exact RefDomainsGOV_Exact ExtBackLinksGOV_Exact LastCrawlDate Title How can i achieve this with PHP? P.S.: I have a scrapper code, that will scrape data for the array $domains, it best if we can merge this code with that code, so all run in one code only. Please Letme know and i will PM you that scrapper Code, as i do not want to share that Publically. Cheers & Enjoy the Snow , Natasha T Link to comment Share on other sites More sharing options...
trq Posted December 5, 2010 Share Posted December 5, 2010 Have you got any code at all? Were not exactly here to write code for people. Link to comment Share on other sites More sharing options...
natasha_thomas Posted December 5, 2010 Author Share Posted December 5, 2010 Have you got any code at all? Were not exactly here to write code for people. Thrope, I appreciate your concern and point. Thing is, i can not post the code here as it will be a piece of cake for Scrappers and i strongly believe there are many who can misuse the scrapper as its a wonderful tool in right hand and deadly in wrong. Thats why i said, i can PM the Codes tho those who are willing to Help. Thanks for the Understanding. Cheers Natasha T Link to comment Share on other sites More sharing options...
laffin Posted December 5, 2010 Share Posted December 5, 2010 Building your own web scraper, i would consider using a toolbox/library that handles html/xml tags. as they can get pretty convoluted. Building your own from scratch, will be specific for certain pages not intended for generalized use. As stated xml/html can get pretty convoluted so will throw off your patterns and such. <?php $data=<<<EOF <?xml version="1.0" encoding="utf-8"?> <Result Code="OK" ErrorMessage="" FullError=""> <GlobalVars IndexBuildDate="17/04/2010 16:43:46" MostRecentBackLinkDate="2010-03-25"/> <DataTables Count="1"> <DataTable Name="Results" RowsCount="1" Headers="ItemNum|Item|ResultCode|Status|ExtBackLinks|RefDomains|AnalysisResUnitsCost|ACRank|ItemType|IndexedURLs|GetTopBackLinksAnalysisResUnitsCost|RefIPs|RefSubNets|RefDomainsEDU|ExtBackLinksEDU|RefDomainsGOV|ExtBackLinksGOV|RefDomainsEDU_Exact|ExtBackLinksEDU_Exact|RefDomainsGOV_Exact|ExtBackLinksGOV_Exact"> <Row>0|majesticseo.com|OK|Found|28381|1229|28381|-1|1|4774|28381|1074|954|1|5|0|0|0|0|0|0</Row> <Row>1|majesticseo.com|OK|Found|28381|1229|28381|-1|1|4774|28381|1074|954|1|5|0|0|0|0|0|0</Row> </DataTable> </DataTables> </Result> EOF; $data=preg_match_all('@<Row>(.*)?</Row>@',$data,$matches); $data=array(); foreach($matches[1] as $match) $data[]=explode('|',$match); print_r($data); Link to comment Share on other sites More sharing options...
trq Posted December 5, 2010 Share Posted December 5, 2010 Thing is, i can not post the code here as it will be a piece of cake for Scrappers and i strongly believe there are many who can misuse the scrapper as its a wonderful tool in right hand and deadly in wrong. You probably shouldn't be asking for help on a public forum then. Hire someone who knows what they are doing. Link to comment Share on other sites More sharing options...
Recommended Posts