scrapeForPhrase function

Future<PhrasePageScrapeResult> scrapeForPhrase(
  1. String phrase
)

Scrape the word page for a word/phrase.

This allows you to get some information that isn't provided by the official API, such as part-of-speech and JLPT level. However, the official API should be preferred if it has the information you need. This function scrapes https://jisho.org/word/XXX. In general, you'll want to include kanji in your search term, for example 掛かる instead of かかる (no results).

Implementation

Future<PhrasePageScrapeResult> scrapeForPhrase(String phrase) async {
  final uri = uriForPhraseScrape(phrase);
  final response = await http.get(uri);
  if (response.statusCode == 404) {
    return PhrasePageScrapeResult(query: phrase);
  }
  return parsePhrasePageData(response.body, phrase);
}