Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function search_rank($keyword, $target, $max_request = 1) {
- $dom = new DOMDocument;
- $url = 'http://search.yahoo.co.jp/search?n=100&p=' . urlencode($keyword);
- for ($i = 0; $i < $max_request; ++$i) {
- @$dom->loadHTMLFile($url);
- $xpath = new DOMXPath($dom);
- foreach ($xpath->query('//*[@id="web"]/ol/li/a/@href') as $j => $node) {
- $value = preg_replace('@^https?+://@', '', $node->nodeValue, 1);
- if (strpos($value, $target) === 0) {
- return $i * 100 + $j;
- }
- }
- if ('' === $url = $xpath->evaluate('string(//*[@id="pg"]/a[string()="次へ »"]/@href)')) {
- break;
- }
- }
- return false;
- }
- $keyword = 'mpyw';
- $target = 'twitter.com/mpyw';
- var_dump(search_rank($keyword, $target, 2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement