Swap dart:html for package:html
This commit is contained in:
parent
0509ac1f61
commit
cbbd60f4c3
|
@ -2,7 +2,7 @@ import 'package:unofficial_jisho_api/src/objects.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:html_unescape/html_unescape.dart' as html_entities;
|
import 'package:html_unescape/html_unescape.dart' as html_entities;
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:html';
|
import 'package:html/parser.dart';
|
||||||
|
|
||||||
final htmlUnescape = html_entities.HtmlUnescape();
|
final htmlUnescape = html_entities.HtmlUnescape();
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ String uriForExampleSearch(String phrase) {
|
||||||
return '${SCRAPE_BASE_URI}${Uri.encodeComponent(phrase)}%23sentences';
|
return '${SCRAPE_BASE_URI}${Uri.encodeComponent(phrase)}%23sentences';
|
||||||
}
|
}
|
||||||
|
|
||||||
ExampleResultData getKanjiAndKana(Element div) {
|
ExampleResultData getKanjiAndKana(div) {
|
||||||
final ul = div.querySelector('ul');
|
final ul = div.querySelector('ul');
|
||||||
final contents = ul.children;
|
final contents = ul.children;
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ ExampleResultData getKanjiAndKana(Element div) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ExampleSentencePiece> getPieces(Element sentenceElement) {
|
List<ExampleSentencePiece> getPieces(sentenceElement) {
|
||||||
final pieceElements = sentenceElement.querySelectorAll('li.clearfix');
|
final pieceElements = sentenceElement.querySelectorAll('li.clearfix');
|
||||||
final pieces = [];
|
final pieces = [];
|
||||||
for (var pieceIndex = 0; pieceIndex < pieceElements.length; pieceIndex += 1) {
|
for (var pieceIndex = 0; pieceIndex < pieceElements.length; pieceIndex += 1) {
|
||||||
|
@ -298,7 +298,7 @@ List<ExampleSentencePiece> getPieces(Element sentenceElement) {
|
||||||
return pieces;
|
return pieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExampleResultData parseExampleDiv(Element div) {
|
ExampleResultData parseExampleDiv(div) {
|
||||||
final result = getKanjiAndKana(div);
|
final result = getKanjiAndKana(div);
|
||||||
result.english = div.querySelector('.english').text;
|
result.english = div.querySelector('.english').text;
|
||||||
result.pieces = getPieces(div);
|
result.pieces = getPieces(div);
|
||||||
|
@ -307,8 +307,7 @@ ExampleResultData parseExampleDiv(Element div) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ExampleResults parseExamplePageData(String pageHtml, String phrase) {
|
ExampleResults parseExamplePageData(String pageHtml, String phrase) {
|
||||||
final parser = DomParser();
|
final document = parse(pageHtml);
|
||||||
final document = parser.parseFromString(pageHtml, 'text/html');
|
|
||||||
final divs = document.querySelectorAll('.sentence_content');
|
final divs = document.querySelectorAll('.sentence_content');
|
||||||
|
|
||||||
final results = divs.map((div) => parseExampleDiv(div));
|
final results = divs.map((div) => parseExampleDiv(div));
|
||||||
|
@ -326,7 +325,7 @@ ExampleResults parseExamplePageData(String pageHtml, String phrase) {
|
||||||
|
|
||||||
/* PHRASE SCRAPE FUNCTIONS START */
|
/* PHRASE SCRAPE FUNCTIONS START */
|
||||||
|
|
||||||
List<String> getTags(Document document) {
|
List<String> getTags(document) {
|
||||||
final tags = [];
|
final tags = [];
|
||||||
final tagElements = document.querySelectorAll('.concept_light-tag');
|
final tagElements = document.querySelectorAll('.concept_light-tag');
|
||||||
|
|
||||||
|
@ -338,7 +337,7 @@ List<String> getTags(Document document) {
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
PhrasePageScrapeResult getMeaningsOtherFormsAndNotes(Document document) {
|
PhrasePageScrapeResult getMeaningsOtherFormsAndNotes(document) {
|
||||||
final returnValues = PhrasePageScrapeResult( otherForms: [], notes: [] );
|
final returnValues = PhrasePageScrapeResult( otherForms: [], notes: [] );
|
||||||
|
|
||||||
// const meaningsWrapper = $('#page_container > div > div > article > div > div.concept_light-meanings.medium-9.columns > div');
|
// const meaningsWrapper = $('#page_container > div > div > article > div > div.concept_light-meanings.medium-9.columns > div');
|
||||||
|
@ -417,8 +416,7 @@ String uriForPhraseScrape(String searchTerm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PhrasePageScrapeResult parsePhrasePageData(String pageHtml, String query) {
|
PhrasePageScrapeResult parsePhrasePageData(String pageHtml, String query) {
|
||||||
final parser = DomParser();
|
final document = parse(pageHtml);
|
||||||
final document = parser.parseFromString(pageHtml, 'text/html');
|
|
||||||
final result = getMeaningsOtherFormsAndNotes(document);
|
final result = getMeaningsOtherFormsAndNotes(document);
|
||||||
|
|
||||||
result.found = true;
|
result.found = true;
|
||||||
|
|
|
@ -10,6 +10,7 @@ dependencies:
|
||||||
# path: ^1.6.0
|
# path: ^1.6.0
|
||||||
xml: ^3.7.0
|
xml: ^3.7.0
|
||||||
html_unescape: ^1.0.1+3
|
html_unescape: ^1.0.1+3
|
||||||
|
html: ^0.14.0+3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
pedantic: ^1.8.0
|
pedantic: ^1.8.0
|
||||||
|
|
Loading…
Reference in New Issue