function scrapeHtml() { $url = "http://nivent.nicovideo.jp/"; $items = array(); $html = file_get_html($url); foreach ($html->find('div[id=list] div[class=box clearfix]') as $key => $html_item) { //データの元 //var_dump($html_item); $title = $html_item->find('div[class=infoUpper] strong a'); $link = $html_item->find('div[class=infoUpper] strong a'); $description = $html_item->find('div[class=infoLower] p[class=body]'); $thumbnail = $html->find('div[class=thumb] img'); //var_dump($link); //アイテムを格納 $item = new Item(); $item->setTitle($title[0]->innertext); $item->setLink("http://nivent.nicovideo.jp" . $link[0]->href); $item->setDescription(createImgTag($thumbnail[$key]->src) . $description[0]->innertext); $items[] = $item; } return $items; }
post_date, post_source_uri, post_source_name, post_category, category_id, category_name FROM post LEFT JOIN category ON category_id = post_category_id WHERE post_valid=1 LIMIT 10'); while ($row = mysql_fetch_object($request)) { // Creating a new feed item $rssItem = new Item(); $rssItem->setTitle($row->post_title); $rssItem->setDescription($row->post_description); $rssItem->setLink('http://www.mywebsite.com/blog/post.php?id=' . $row->post_id); $rssItem->setGuid('http://www.mywebsite.com/blog/post.php?id=' . $row->post_id, true); $rssItem->setComments('http://www.mywebsite.com/blog/post.php?id=' . $row->post_id . '#comments'); $rssItem->setAuthor($row->post_author_email, $row->post_author_name); $rssItem->setPubDate($row->post_date); $rssItem->setSource($row->post_source_uri, $row->post_source_name); $rssItem->setEnclosure('http://www.mywebsite.com/blog/images/nopicture.jpg', 2800, 'image/jpg'); $rssItem->setCategory('http://www.mywebsite.com/blog/category.php.idCat=' . $row->category_id, $row->category_name); // Add the item to the feed $rssFeed->appendItem($rssItem); } // Save the feed $rssFeed->save(); // SQL connection closing mysql_close(); // Send headers to the browser
/** * @dataProvider toHtmlDataProvider * * @param array $liParams * @param string $attrName * @param string $attrValue * @param string $innerText */ public function testToHtml($liParams, $attrName, $attrValue, $innerText) { $this->item->setLink($liParams, $innerText); $this->assertTag(['tag' => 'li', 'attributes' => [$attrName => $attrValue], 'content' => $innerText], $this->item->toHtml()); }
foreach ($feeds as $feed) { $channel = $feed->getElementsByTagName('channel')->item(0); // the whole channel element $channelTitle = $channel->getElementsByTagName('link')->item(0)->nodeValue; // channel title $items = $feed->getElementsByTagName('item'); // All items in this feed foreach ($items as $key) { $title = $key->getElementsByTagName('title')->item(0)->nodeValue; $link = $key->getElementsByTagName('link')->item(0)->nodeValue; $description = $key->getElementsByTagName('description')->item(0)->nodeValue; $pubDate = $key->getElementsByTagName('pubDate')->item(0)->nodeValue; $item = new Item(); $item->setMedia($channelTitle); $item->setTitle($title); $item->setLink($link); $item->setDescription($description); $item->setPubDate($pubDate); $result[] = $item; } } usort($result, 'compareByDate'); function compareByDate(Item $a, Item $b) { $a = strtotime($a->getPubDate()); $b = strtotime($b->getPubDate()); if ($a == $b) { return 0; } return $a < $b ? 1 : -1; }
/** * @covers Debril\RssAtomBundle\Protocol\Parser\Item::setLink */ public function testSetLink() { $newLink = 'http://example.com/atom'; $this->object->setLink($newLink); $this->assertEquals($newLink, $this->object->getLink()); }