息子の研究プロジェクトのために、Alexaから最新の「What'shot」トピックを取得しようとしています。基本的には、単語を取得してmysqlデータベースに挿入したいだけです。
私が現在持っているものは次のとおりです。
<?php
function getAlexa($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$grab = getAlexa("http://www.alexa.com/whatshot");
// missing part to get everything between title=''
// mysql connection details are included
include "connectiondetails.php";
// mysql table setup is id (int 11) AI, word (varchar 100) UNIQUE
$insert = @mysql_query("INSERT IGNORE INTO words values('','$word')");
?>
私の問題は、私がまだPHPに慣れていないため、alexa.com / whatshotからすべてのahrefタイトル(短縮されたアンカーテキストではない)を取得する必要があることです。たとえば、title='と次の'の間のすべての場合と同様です。 ='hello world'は、単語(文字列)がhelloworldになることを意味します-20個の単語すべてを取得するためにこれが必要です。
構造は次のとおりです。
<a href='http://www.alexa.com/whatshot?q=loretta+swit+turns+75' title='Loretta Swit Turns 75'>Loretta Swit Turns 75</a></li><li>2. <a href='http://www.alexa.com/whatshot?q=where+do+i+vote' title='where do I vote'>where do I vote</a></li><li>3. <a href='http://www.alexa.com/whatshot?q=nj+earthquake' title='NJ earthquake'>NJ earthquake</a></li><li>4. <a href='http://www.alexa.com/whatshot?q=yvonne+strahovski' title='Yvonne Strahovski'>Yvonne Strahovski</a></li><li>5. <a href='http://www.alexa.com/whatshot?q=early+voting+results' title='early voting results'>early voting results</a></li></ul><ul class='hotsearches' start='6'><li>6. <a href='http://www.alexa.com/whatshot?q=milt+campbell+dies' title='Milt Campbell Dies'>Milt Campbell Dies</a></li><li>7. <a href='http://www.alexa.com/whatshot?q=bristol+palin+suit+tossed' title='Bristol Palin suit tossed'>Bristol Palin suit...</a></li><li>8. <a href='http://www.alexa.com/whatshot?q=a+gay+lesbian' title='a gay lesbian'>a gay lesbian</a></li><li>9. <a href='http://www.alexa.com/whatshot?q=navy+skipper+fired' title='Navy skipper fired'>Navy skipper fired</a></li><li>10. <a href='http://www.alexa.com/whatshot?q=single+mom+no+tip' title='single mom no tip'>single mom no tip</a></li></ul><ul class='hotsearches' start='11'><li>11. <a href='http://www.alexa.com/whatshot?q=craigslist' title='craigslist'>craigslist</a></li><li>12. <a href='http://www.alexa.com/whatshot?q=nate+silver' title='Nate Silver'>Nate Silver</a></li><li>13. <a href='http://www.alexa.com/whatshot?q=real+clear+politics' title='real Clear Politics'>real Clear Politics</a></li><li>14. <a href='http://www.alexa.com/whatshot?q=93-year-old+bodybuilder' title='93-year-old bodybuilder'>93-year-old bodybu...</a></li><li>15. <a href='http://www.alexa.com/whatshot?q=wreck+it+ralph' title='Wreck It Ralph'>Wreck It Ralph</a></li></ul><ul class='hotsearches' start='16'><li>16. <a href='http://www.alexa.com/whatshot?q=kickstarter' title='Kickstarter'>Kickstarter</a></li><li>17. <a href='http://www.alexa.com/whatshot?q=african+painted+dogs' title='African painted dogs'>African painted dogs</a></li><li>18. <a href='http://www.alexa.com/whatshot?q=red+dawn' title='Red Dawn'>Red Dawn</a></li><li>19. <a href='http://www.alexa.com/whatshot?q=instagram' title='Instagram'>Instagram</a></li><li>20. <a href='http://www.alexa.com/whatshot?q=iphone+5' title='iPhone 5'>iPhone 5</a>
したがって、すべてがうまくいけば、グラブが完了すると、データベースに20語が含まれることになります。
お時間を割いていただきありがとうございます。
あなたの助けは大歓迎です。