ios - Swift 如何从实时网站中抓取前 500 或 1000 个顶级网站?
问题描述
首先,我不知道从https://gtmetrix.com/top1000.html抓取数据是否合适,但我想为我的应用获取前 500 或 1000 个网站的列表。因此,当用户搜索某个网站时,该应用程序可以提供建议的结果。
我正在尝试通过以下代码获取本网站的 html 内容
let url = URL(string:"https://gtmetrix.com/top1000.html")
do{
let html = try String(contentsOf: url!, encoding: String.Encoding.ascii)
print(html)
}catch {
print("woops")
}
但是html字符串似乎不一致,并且不包含我想要的信息,例如标签tbody和/tbody之间缺少的部分应该包含我需要的信息。我可以使用 Chrome 中的开发者工具查看内容。
这是否意味着这里的数据是保护性的,不允许刮取?
还有其他资源和方法可以实现我的目标吗?
提前致谢。
<table id="top-1000" class="t1k-table styled-table">
<thead>
<tr>
<th class="t1k-rank">Rank</th>
<th class="t1k-url">URL</th>
<th class="t1k-pagespeed">PageSpeed</th>
<th class="t1k-yslow">YSlow</th>
<th class="t1k-time">Onload</th>
<th class="t1k-time">Fully Loaded</th>
<th class="t1k-elements">Requests</th>
<th class="t1k-size">Total Size</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
解决方案
推荐阅读
- arrays - 将二维数组传递给函数
- javascript - 当浏览器进行屏幕缩放时,ScreenX 和 ScreenY 不会将元素与光标对齐
- java - 计算节点上的代理数
- python - 从具有相同类 bs4 beautifulSoup 的不同元素中提取多个字符串
- command-line - jq 从文件中读取过滤器导致无效的语法错误
- r - 将某些数字与模数函数一起使用时,模数警告和不正确的结果可能会完全丧失准确性
- c - 打印给定年份和月份的日历
- python - 在python中打印一个二维数组
- azure-policy - 我有哪些选项可以调试自定义 Azure 策略或评估策略引擎之外的字段?
- linux - 使用 bash 对使用 Openssl 加密的文件进行暴力破解