Skip to content

Commit

Permalink
Fix crawler of Eromon plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
app2641 committed Nov 23, 2015
1 parent d3684a8 commit 7eb0f81
Show file tree
Hide file tree
Showing 8 changed files with 1,252 additions and 1,069 deletions.
561 changes: 305 additions & 256 deletions data/fixtures/html/eromon/4366.html

Large diffs are not rendered by default.

561 changes: 305 additions & 256 deletions data/fixtures/html/eromon/4367.html

Large diffs are not rendered by default.

559 changes: 305 additions & 254 deletions data/fixtures/html/eromon/4368.html

Large diffs are not rendered by default.

575 changes: 321 additions & 254 deletions data/fixtures/html/eromon/4370.html

Large diffs are not rendered by default.

42 changes: 16 additions & 26 deletions src/Midnight/Crawler/Plugin/Eromon.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@

class Eromon extends AbstractPlugin implements PluginInterface
{

/**
* サイト名
*
* @var string
**/
protected $site_name = 'えろもん';


/**
* RSSフィードのURL
*
* @var string
**/
protected $rss_url = 'http://erovi0.blog.fc2.com/?xml';



/**
* DOMElementからエントリのURLを返す
*
Expand All @@ -37,7 +33,6 @@ public function getEntryUrl ($entry)
return $this->getNodeValueByTagName($entry, 'link');
}


/**
* エントリの登録された日付を取得する
*
Expand All @@ -49,7 +44,6 @@ public function getEntryDate ($entry)
return $this->getDateByDcDate($entry);
}


/**
* エントリのタイトルを取得する
*
Expand All @@ -58,14 +52,13 @@ public function getEntryDate ($entry)
**/
public function getEntryTitle ($html)
{
$query = 'div#container div#content div.entry_body div.entry_middle h2 a';
$query = 'div#main_contents div.content h2.entry_header';
$title_el = $html->find($query, 0);
if (is_null($title_el)) throw new CrawlerException('タイトルを取得出来ませんでした');

return $title_el->plaintext;
}


/**
* アイキャッチ画像のURLを取得する
*
Expand All @@ -74,13 +67,13 @@ public function getEntryTitle ($html)
**/
public function getEyeCatchUrl ($html)
{
$query = 'div#container div#content div.entry_body div.entry_middle div.entry_text div img';
$query = 'div#main_contents div.content div.entry_body div img';
$img_el = $html->find($query, 0);

// img要素の親にdivを挟んでいるパターンのページも存在するため
// 二重でクエリを発行して確認している
if (is_null($img_el)) {
$query = 'div#container div#content div.entry_body div.entry_middle div.entry_text img';
$query = 'div#main_contents div.content div.entry_body img';
$img_el = $html->find($query, 0);
}
if (is_null($img_el)) throw new CrawlerException('アイキャッチを取得出来ませんでした');
Expand All @@ -89,7 +82,6 @@ public function getEyeCatchUrl ($html)
return $img_el->getAttribute('src');
}


/**
* 動画のURLを取得する
*
Expand All @@ -98,7 +90,7 @@ public function getEyeCatchUrl ($html)
**/
public function getMoviesUrl ($html)
{
$query = 'div#container div#content div.entry_middle div.entry_text iframe';
$query = 'div#main_contents div.content div.entry_body iframe';
$movies_els = $html->find($query);
$movie_data = array();
$manager = new UriManager();
Expand All @@ -114,28 +106,26 @@ public function getMoviesUrl ($html)
}
}

if (count($movie_data) > 0) return $movie_data;

// if (count($movie_data) > 0) return $movie_data;

// div.entry_more_text以下にiframeがある場合もある
$query = 'div#container div#content div.entry_middle div.entry_more_text iframe';
$movies_els = $html->find($query);
// $query = 'div#container div#content div.entry_middle div.entry_more_text iframe';
// $movies_els = $html->find($query);

// 動画はこちらテキストのリンクを取得する
foreach ($movies_els as $movies_el) {
// iframeの次の次の要素であるa要素を取得する
$link_el = $this->_fetchMovieLinkElement($movies_el);
if (is_null($link_el)) continue;
// // 動画はこちらテキストのリンクを取得する
// foreach ($movies_els as $movies_el) {
// // iframeの次の次の要素であるa要素を取得する
// $link_el = $this->_fetchMovieLinkElement($movies_el);
// if (is_null($link_el)) continue;

if ($link_el->nodeName() === 'a') {
$movie_data[] = $manager->resolve($link_el->getAttribute('href'));
}
}
// if ($link_el->nodeName() === 'a') {
// $movie_data[] = $manager->resolve($link_el->getAttribute('href'));
// }
// }

return $movie_data;
}


/**
* 動画urlの指定されたa要素を取得する
*
Expand Down
2 changes: 0 additions & 2 deletions src/Midnight/Crawler/Plugin/TestData/EromonTestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@

class EromonTestData extends AbstractTestData
{

/**
* @var string
**/
protected $rss_name = 'eromon.xml';


/**
* @var array
**/
Expand Down
18 changes: 0 additions & 18 deletions tests/Midnight/Crawler/Plugin/EromonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@

class EromonTest extends PHPUnit_Framework_TestCase
{

/**
* @var Eromon
**/
private $plugin;


/**
* @var EromonTestData
**/
private $test_data;


/**
* セットアップ
*
Expand All @@ -32,7 +29,6 @@ public function setUp ()
$this->plugin->setTestData($this->test_data);
}


/**
* @test
* @expectedException CrawlerException
Expand All @@ -55,7 +51,6 @@ public function RSSが取得出来なかった場合 ()
$this->plugin->fetchRss();
}


/**
* @test
* @group eromon
Expand All @@ -67,7 +62,6 @@ public function RSSを取得する ()
$this->assertInstanceOf('DOMDocument', $dom);
}


/**
* @test
* @group eromon
Expand All @@ -81,7 +75,6 @@ public function コンテンツ要素を取得する ()
$this->assertFalse(is_null($entries->item(0)));
}
/**
* @test
* @group eromon
Expand All @@ -96,7 +89,6 @@ public function エントリのURLを取得する ()
$this->assertEquals('http://erovi0.blog.fc2.com/blog-entry-4370.html', $url);
}


/**
* @test
* @group eromon-get-entry-date
Expand All @@ -111,7 +103,6 @@ public function エントリの日付を取得する ()
$this->assertEquals('2015-03-03', $date);
}


/**
* @test
* @medium
Expand All @@ -124,7 +115,6 @@ public function HTMLを取得する ()
$this->assertInstanceOf('simple_html_dom', $html);
}


/**
* @test
* @medium
Expand All @@ -139,7 +129,6 @@ public function エントリのタイトルを取得する ()
$this->assertEquals('メルシーボークー DV 16 放課後Hなアルバイト : 尾上若葉', $title);
}


/**
* @test
* @medium
Expand All @@ -156,7 +145,6 @@ public function エントリのタイトルを取得出来なかった場合 ()
$this->plugin->getEntryTitle($html);
}


/**
* @test
* @medium
Expand All @@ -176,7 +164,6 @@ public function アイキャッチ画像のURLを取得する ()
$this->assertEquals('http://blog-imgs-75-origin.fc2.com/e/r/o/erovi0/apak088sops.jpg', $img_url);
}


/**
* @test
* @medium
Expand All @@ -193,7 +180,6 @@ public function アイキャッチの画像要素が見つからなかった場
$this->plugin->getEyeCatchUrl($html);
}


/**
* @test
* @medium
Expand All @@ -210,7 +196,6 @@ public function src属性が見つからなかった場合 ()
$this->plugin->getEyeCatchUrl($html);
}


/**
* @test
* @medium
Expand All @@ -229,7 +214,6 @@ public function 動画へのリンクを取得する1 ()
);
}


/**
* @test
* @medium
Expand All @@ -247,7 +231,6 @@ public function 動画へのリンクを取得する2 ()
);
}


/**
* @test
* @medium
Expand All @@ -266,7 +249,6 @@ public function 動画へのリンクを取得する3 ()
);
}


/**
* @test
* @medium
Expand Down
3 changes: 0 additions & 3 deletions tests/Midnight/Crawler/Plugin/TestData/EromonTestDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class EromonTestDataTest extends PHPUnit_Framework_TestCase
**/
private $test_data;


/**
* @return void
**/
Expand All @@ -22,7 +21,6 @@ public function setUp ()
$this->test_data = $container->get('Eromon');
}


/**
* @test
* @group eromon-test
Expand All @@ -34,7 +32,6 @@ public function テスト用RSSデータのパスを取得する ()
$this->assertEquals(ROOT.'/data/fixtures/rss/eromon.xml', $rss_path);
}


/**
* @test
* @group eromon-test
Expand Down

0 comments on commit 7eb0f81

Please sign in to comment.