html - Flutter:从网站获取“原始” html 文档
问题描述
我对(颤振)开发相当陌生,我有一个问题:
有这个网站,我想在应用程序中显示内容。据我了解该网站,它是一个服务器站点 html 渲染。由于没有可用于读取数据的 API(至少我没有找到它们),我想获取整个 html 文档并解析所有“有趣”的数据。
您知道如何获取 html 文档以便开始解析吗?还是有更优雅的解决方案来解决我的问题?
信息:我不想制作 html 渲染,我已经构建了自己的 UI,只想插入特定数据
提前非常感谢!
解决方案
我刚刚http.get
在 Flutter 上测试了一个对您指定的 url 的请求并且运行良好。我使用这个包发出 get 请求,我定义了一个异步函数来发出请求,并在main
Flutter 应用程序的函数中调用该函数:
//This import the package
import 'package:http/http.dart' as http;
//...
//Here comes code of Flutter
//...
//Now I define the async function to make the request
void makeRequest() async{
var response = await http.get('https://speiseplan.app.itelligence.org/');
//If the http request is successful the statusCode will be 200
if(response.statusCode == 200){
String htmlToParse = response.body;
print(htmlToParse);
}
}
//...
//Here comes more Flutter code
//...
main(){
makeRequest();
}
这会将您想要的 html 打印为字符串,现在您可以根据需要对其进行解析。
推荐阅读
- python - 尝试在分配局部变量之前打印它的值
- javascript - javascript在本地主机上工作正常,但在实时服务器上却不行
- angular5 - 如何禁用 mat-list-item 的点击事件启用仅 maticon 的点击
- racket - 语法分析中的非语法语法
- business-intelligence - 需要有关处理 informatica 错误“值大于指定精度允许此列”的策略的建议,因为它会导致重复失败
- python - smtp2go 用户名的账户不允许发送
- javascript - 向旋转元素添加了过渡属性,但它以 0 度向后移动?
- java - 如何在recyclerview android的意图字符串数组中显示收入?
- git - 清理 git 存储库
- excel - Excel VBA 脚本/大型列表创建中的溢出问题