瀏覽代碼

updated BioBioChile

Pablo 1 周之前
父節點
當前提交
1f19a78fac
共有 2 個文件被更改,包括 10 次插入3 次删除
  1. 2 2
      src/portales/biobiochile/handler.ts
  2. 8 1
      src/utils/scraper-articles.ts

+ 2 - 2
src/portales/biobiochile/handler.ts

@@ -11,10 +11,10 @@ export const handler: Handler = new Portal(
   config.MASTODON_KEY_BIOBIOCHILE,
   {
     url: config.BIOBIOCHILE,
-    articlesSelector: "article.main-article, article.article-highlights, article.article-horizontal, article.vertical, article.article-highlights-aside",
+    articlesSelector: "article",
     titleSelector: ".article-title:first",
     linkSelector: "a",
-    scraperMethod: ScraperMethods.AXIOS,
+    scraperMethod: ScraperMethods.PUPPETEER,
     hashtags: ["BioBioChile", "Noticias"]
   }
 ).getHandler();

+ 8 - 1
src/utils/scraper-articles.ts

@@ -48,7 +48,14 @@ export default class ScraperArticles {
 
   private getLink(article: AnyNode): string {
     const selector = this._options.linkSelector ?? "";
-    const url = selector !== "" ? this.getProperty(article, selector, Props.LINK) : this._options.url
+    let url = selector !== "" ? this.getProperty(article, selector, Props.LINK) : this._options.url
+
+    // Fallback: when the article itself is wrapped by an anchor (e.g. BioBioChile)
+    // and the configured linkSelector does not find a descendant link.
+    if (!url && selector !== "") {
+      const $ = load(article);
+      url = $(article).closest("a").attr("href") ?? "";
+    }
 
     return !this.isValidUrl(url) && this._options.linkPrefix !== undefined
       ? (this._options.linkPrefix + url.trim()).trim()