fix thiladhun
This commit is contained in:
@@ -18,22 +18,23 @@ class ThiladhunFeed implements Feed
|
|||||||
*/
|
*/
|
||||||
public function get() : array
|
public function get() : array
|
||||||
{
|
{
|
||||||
|
|
||||||
$crawler = $this->client->request('GET', "https://www.thiladhun.com");
|
$crawler = $this->client->request('GET', "https://www.thiladhun.com");
|
||||||
|
|
||||||
$feeds = [];
|
$feeds = [];
|
||||||
$crawler->filter('div[class*="posts-listing posts-list"] article')->each(function ($node) use (&$feeds) {
|
// Assuming 'ފަހުގެ' is a unique identifier for the section of interest
|
||||||
|
$crawler->filter('.elementor-element:contains("ފަހުގެ")')->nextAll('.elementor-post')->each(function ($node) use (&$feeds) {
|
||||||
|
$title = $node->filter('.elementor-heading-title a')->count() ? $node->filter('.elementor-heading-title a')->text() : null;
|
||||||
$feeds[] = [
|
$link = $node->filter('.elementor-heading-title a')->count() ? $node->filter('.elementor-heading-title a')->attr('href') : null;
|
||||||
"title" => $node->filter('.post__title a')->text(),
|
|
||||||
"link" => $node->filter('.post__title a')->attr('href'),
|
|
||||||
"date" => $node->filter('time')->first()->attr('datetime')
|
|
||||||
];
|
|
||||||
|
|
||||||
|
if ($title && $link) {
|
||||||
|
$feeds[] = [
|
||||||
|
"title" => $title,
|
||||||
|
"link" => $link,
|
||||||
|
];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $feeds;
|
return $feeds;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class ThiladhunScraper
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function extract($url, $date)
|
public function extract($url)
|
||||||
{
|
{
|
||||||
|
|
||||||
$crawler = $this->client->request('GET', $url);
|
$crawler = $this->client->request('GET', $url);
|
||||||
@@ -51,20 +51,23 @@ class ThiladhunScraper
|
|||||||
$this->image = $crawler->filter('div[data-widget_type*="theme-post-featured-image.default"] figure img')->first()->attr('src');
|
$this->image = $crawler->filter('div[data-widget_type*="theme-post-featured-image.default"] figure img')->first()->attr('src');
|
||||||
|
|
||||||
$crawler->filter('.entry-tags a')->each(function ($node) {
|
$crawler->filter('.entry-tags a')->each(function ($node) {
|
||||||
if(!preg_match('/[^A-Za-z0-9-]/', basename($node->attr('href'))))
|
if (!preg_match('/[^A-Za-z0-9-]/', basename($node->attr('href')))) {
|
||||||
{
|
$this->topics[] = [
|
||||||
$this->topics[] = [
|
"name" => $node->text(),
|
||||||
"name" => $node->text(),
|
"slug" => basename($node->attr('href'))
|
||||||
"slug" => basename($node->attr('href'))
|
];
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
|
||||||
|
|
||||||
$crawler->filter('a > .elementor-post-info__item--type-author')->each(function ($node) {
|
$crawler->filter('a > .elementor-post-info__item--type-author')->each(function ($node) {
|
||||||
$this->author = $node->text();
|
$this->author = $node->text();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$urlComponents = parse_url($url);
|
||||||
|
$cleanUrl = $urlComponents['scheme'] . '://' . $urlComponents['host'] . $urlComponents['path'];
|
||||||
|
|
||||||
|
// Extract and modify the guid
|
||||||
|
$guid = basename($urlComponents['path']);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'source' => 'Thiladhun News',
|
'source' => 'Thiladhun News',
|
||||||
@@ -72,11 +75,11 @@ class ThiladhunScraper
|
|||||||
'og_title' => str_replace(" | Thiladhun", "", $crawler->filter('title')->first()->text('content')),
|
'og_title' => str_replace(" | Thiladhun", "", $crawler->filter('title')->first()->text('content')),
|
||||||
'image' => $this->image,
|
'image' => $this->image,
|
||||||
'content' => $this->content,
|
'content' => $this->content,
|
||||||
'date' => Carbon::parse($date)->format("Y-m-d H:i:s"),
|
'date' => Carbon::now(),
|
||||||
'url' => $url,
|
'url' => $cleanUrl,
|
||||||
'author' => $this->author,
|
'author' => $this->author,
|
||||||
'guid' => basename($url),
|
'guid' => $guid,
|
||||||
'topics' => $this->topics ? : [
|
'topics' => $this->topics ?: [
|
||||||
[
|
[
|
||||||
"name" => "ވަކި މަޢުލޫއެއް ނޭންގެ",
|
"name" => "ވަކި މަޢުލޫއެއް ނޭންގެ",
|
||||||
"slug" => "no-specific-topic"
|
"slug" => "no-specific-topic"
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ class ThiladhunService extends Client
|
|||||||
$response = Http::get("https://thiladhun.com/feed")->body();
|
$response = Http::get("https://thiladhun.com/feed")->body();
|
||||||
$data = json_decode(json_encode(simplexml_load_string($response)), true);
|
$data = json_decode(json_encode(simplexml_load_string($response)), true);
|
||||||
$articles = $data["channel"]["item"];
|
$articles = $data["channel"]["item"];
|
||||||
|
|
||||||
$articlesitems = [];
|
$articlesitems = [];
|
||||||
//Looping through the articles and scraping and while scraping it creates a new instance of the scraper.
|
//Looping through the articles and scraping and while scraping it creates a new instance of the scraper.
|
||||||
foreach ($articles as $article) {
|
foreach ($articles as $article) {
|
||||||
//Remove query strings
|
//Remove query strings
|
||||||
$articlesitems[] = (new ThiladhunScraper)->extract(Str::before($article["link"], '?'), $article["pubDate"]);
|
$articlesitems[] = (new ThiladhunScraper)->extract($article["link"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $articlesitems;
|
return $articlesitems;
|
||||||
|
|||||||
Reference in New Issue
Block a user