You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code snippet below is supposed to scrap all the sentences showed on https://jisho.org/search/%E6%97%A5%20%23sentences; however, the sentences after the execution of the function does not contain proper results.
For example, the selector #secondary > div > ul > li:nth-child(2) > div.sentence_content > ul > li:nth-child(1) > span.unlinked should return the element <span class="unlinked">今日</span> instead, it retuens null
List<Sentence> parseHtml() async {
List<Sentence> sentences = [];
Client client = Client();
Response response = await client.get('https://jisho.org/search/%E6%97%A5%20%23sentences');
var doc = parse(response.body);
int childIndex;
for (int i = 1; i <= 20; i++) {
childIndex = 1;
List<Token> tokens = [];
while (true) {
var element =
doc.querySelector('#secondary > div > ul > li:nth-child($i) > div.sentence_content > ul > li:nth-child($childIndex) > span.unlinked');
//print(element.text);
if (element == null) break;
var text = element.text;
print("the i is $i and the currentIndex is $childIndex and the text is $text");
element =
doc.querySelector('#secondary > div > ul > li:nth-child($i) > div.sentence_content > ul > li:nth-child($childIndex) > span.furigana');
if (element == null) {
tokens.add(Token(text: text));
} else {
var furigana = element.text;
tokens.add(Token(text: text, furigana: furigana));
}
childIndex++;
}
var sentence = Sentence(tokens: tokens);
print(sentence.text);
this.sentences.add(sentence);
sentences.add(Sentence());
}
return sentences;
}
class Token {
String text;
String furigana;
Token({@required this.text, this.furigana});
}
class Sentence {
List<Token> tokens;
String text = '';
Sentence({this.tokens}) {
for (var token in tokens) {
text += token.text;
}
}
}
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
The code snippet below is supposed to scrap all the sentences showed on https://jisho.org/search/%E6%97%A5%20%23sentences; however, the
sentences
after the execution of the function does not contain proper results.For example, the selector
#secondary > div > ul > li:nth-child(2) > div.sentence_content > ul > li:nth-child(1) > span.unlinked
should return the element<span class="unlinked">今日</span>
instead, it retuensnull
The text was updated successfully, but these errors were encountered: