Skip to content

Commit

Permalink
fix url
Browse files Browse the repository at this point in the history
  • Loading branch information
ksh-b committed Aug 3, 2024
1 parent c0f83dd commit 56ccccc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 36 deletions.
2 changes: 1 addition & 1 deletion lib/extractor/technology/androidpolice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AndroidPolice extends Publisher {
Future<Set<NewsArticle>> categoryArticles(
{String category = "", int page = 1}) async {
Set<NewsArticle> articles = {};
await dio().get("$homePage/news/$page").then((response) {
await dio().get("$homePage/$category/$page").then((response) {
if (response.statusCode == 200) {
Document document = html_parser.parse(response.data);
List<Element> articleElements =
Expand Down
87 changes: 52 additions & 35 deletions lib/extractor/technology/xdadevelopers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ class XDAdevelopers extends Publisher {
Category get mainCategory => Category.technology;

@override
String get iconUrl => "https://www.xda-developers.com/public/build/images/favicon-48x48.8f822f21.png";
String get iconUrl =>
"https://www.xda-developers.com/public/build/images/favicon-48x48.8f822f21.png";

@override
Future<NewsArticle> article(NewsArticle newsArticle) async {
await dio().get("$homePage${newsArticle.url}").then((response) {
if (response.statusCode == 200) {
Document document = html_parser.parse(response.data);
String? content = document.querySelector(".article-body")?.innerHtml;
List<String> related = document.querySelectorAll(".no-badge.small").map((e) => e.innerHtml).toList();
List<String> related = document
.querySelectorAll(".no-badge.small")
.map((e) => e.innerHtml)
.toList();
for (String rel in related) {
content = content?.replaceFirst(rel, "");
}
Expand All @@ -47,8 +51,7 @@ class XDAdevelopers extends Publisher {
(response) {
if (response.statusCode == 200) {
var document = html_parser.parse(response.data);
document.querySelectorAll(".sidenav-link")
.forEach((element) {
document.querySelectorAll(".sidenav-link").forEach((element) {
map.putIfAbsent(
element.text.trim(),
() {
Expand All @@ -67,28 +70,36 @@ class XDAdevelopers extends Publisher {
Future<Set<NewsArticle>> categoryArticles(
{String category = "", int page = 1}) async {
Set<NewsArticle> articles = {};
await dio().get("$homePage/news/$page").then((response) {
await dio().get("$homePage/$category/$page").then((response) {
if (response.statusCode == 200) {
Document document = html_parser.parse(response.data);
List<Element> articleElements =
document.querySelectorAll(".listing-content .article");
for (Element articleElement in articleElements) {
String? title = articleElement.querySelector(".display-card-title")?.text;
String? excerpt = articleElement.querySelector(".display-card-excerpt")?.text;
String? author = articleElement.querySelector(".display-card-author")?.text;
String? url = articleElement.querySelector(".display-card-title a")?.attributes["href"];
String? title =
articleElement.querySelector(".display-card-title")?.text;
String? excerpt =
articleElement.querySelector(".display-card-excerpt")?.text;
String? author =
articleElement.querySelector(".display-card-author")?.text;
String? url = articleElement
.querySelector(".display-card-title a")
?.attributes["href"];
var tags = articleElement
.querySelectorAll(".listing-title")
.map((e) => e.text)
.toList();
String? thumbnail = articleElement
.querySelector("picture img")
?.attributes["src"];
String? content = articleElement.querySelector(".display-card-firstParagraph")?.text;
String? date = articleElement.querySelector(".display-card-date")?.text;
int parsedTime = relativeStringToUnix(date??"");
String? thumbnail =
articleElement.querySelector("picture img")?.attributes["src"];
String? content = articleElement
.querySelector(".display-card-firstParagraph")
?.text;
String? date =
articleElement.querySelector(".display-card-date")?.text;
int parsedTime = relativeStringToUnix(date ?? "");

articles.add(NewsArticle(
articles.add(
NewsArticle(
publisher: name,
title: title?.trim() ?? "",
content: content ?? "",
Expand All @@ -98,7 +109,9 @@ class XDAdevelopers extends Publisher {
thumbnail: thumbnail ?? "",
publishedAt: parsedTime,
tags: tags,
category: category));
category: category,
),
);
}
}
});
Expand All @@ -116,31 +129,35 @@ class XDAdevelopers extends Publisher {
List<Element> articleElements =
document.querySelectorAll(".listing-content .article");
for (Element articleElement in articleElements) {
String? title = articleElement.querySelector(".display-card-title")?.text;
String? excerpt = articleElement.querySelector(".display-card-excerpt")?.text;
String? author = articleElement.querySelector(".display-card-author")?.text;
String? url = articleElement.querySelector(".display-card-title a")?.attributes["href"];
String? title =
articleElement.querySelector(".display-card-title")?.text;
String? excerpt =
articleElement.querySelector(".display-card-excerpt")?.text;
String? author =
articleElement.querySelector(".display-card-author")?.text;
String? url = articleElement
.querySelector(".display-card-title a")
?.attributes["href"];
var tags = articleElement
.querySelectorAll(".listing-title")
.map((e) => e.text)
.toList();
String? thumbnail = articleElement
.querySelector("picture img")
?.attributes["src"];
String? thumbnail =
articleElement.querySelector("picture img")?.attributes["src"];
String? date = articleElement.querySelector(".display-card-date")?.text;
int parsedTime = relativeStringToUnix(date??"");
int parsedTime = relativeStringToUnix(date ?? "");

articles.add(NewsArticle(
publisher: name,
title: title?.trim() ?? "",
content: "",
excerpt: excerpt ?? "",
author: author ?? "",
url: url?.replaceFirst(homePage, "") ?? "",
thumbnail: thumbnail ?? "",
publishedAt: parsedTime,
tags: tags,
category: searchQuery));
publisher: name,
title: title?.trim() ?? "",
content: "",
excerpt: excerpt ?? "",
author: author ?? "",
url: url?.replaceFirst(homePage, "") ?? "",
thumbnail: thumbnail ?? "",
publishedAt: parsedTime,
tags: tags,
category: searchQuery,),);
}
}
return articles;
Expand Down

0 comments on commit 56ccccc

Please sign in to comment.