Skip to content

Instantly share code, notes, and snippets.

@apgapg
Created July 19, 2020 07:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apgapg/ebfaae6be8891a2917db8016f3050be4 to your computer and use it in GitHub Desktop.
Save apgapg/ebfaae6be8891a2917db8016f3050be4 to your computer and use it in GitHub Desktop.
Scrap data from website
void initChaptersTitleScrap() async {
final rawUrl =
'https://unacademy.com/course/gravitation-for-iit-jee/D5A8YSAJ';
final webScraper = WebScraper('https://unacademy.com');
final endpoint = rawUrl.replaceAll(r'https://unacademy.com', '');
if (await webScraper.loadWebPage(endpoint)) {
final titleElements = webScraper.getElement(
'div.Week__Wrapper-sc-1qeje5a-2 > a.Link__StyledAnchor-sc-1n9f3wx-0 '
'> div.ItemCard__ItemInfo-xrh60s-1 '
'> h6.H6-sc-1gn2suh-0',
[]);
print(titleElements);
final titleList = <String>[];
titleElements.forEach((element) {
final title = element['title'];
titleList.add('$title');
});
print(titleList);
if (mounted)
setState(() {
this.titleList = titleList;
});
} else {
print('Cannot load url');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment