javascript - 使用隐藏元素抓取动态网站
问题描述
目的是抓取booking.com以显示所有价格。为此,我使用 PhantomJS 运行下面的 javascript 代码,然后将网页的内容写入本地 html 文件。
var url = 'https://www.booking.com/searchresults.html?ss=Copenhagen%20Denmark&checkin_year=2020&checkin_month=2&checkin_monthday=6&checkout_year=2020&checkout_month=2&checkout_monthday=9&group_adults=2&group_children=0&no_rooms=1&no_dorms=1&nflt=pri%3D1%3Bpri%3D2%3B';
var page = require('webpage').create();
var fs = require('fs');
page.onLoadFinished = function() {
fs.write('result.html', page.content, 'w');
phantom.exit();
};
page.open(url, function() {
page.evaluate(function() {
});
});
问题是没有读取价格,结果看起来像这样(所有过滤器都丢失了,控制台中记录了一些警告和错误)
例如,以下是一些应该被抓取的元素:
<div class="bui-price-display__value prco-inline-block-maker-helper" aria-hidden="true">
€&nbsp;246
</div>
<span class="bui-u-sr-only">
Preis
€&nbsp;246
</span>
如果 PhantomJS 无法做到这一点,还有其他选择吗?我也尝试过 cURL 但无济于事。
解决方案
推荐阅读
- python-3.x - Spark 在到达过滤器功能时杀死作业,错误火花请求执行器仅在粗粒度模式下支持
- javascript - 如何绑定一个
- google-sheets - 在 Google 表格中使用 VLOOKUP 搜索字符串
- sql - 将星期几存储在单个列中的最佳方法
- javascript - 如何使用非递归算法填充区域?
- python - 如何查找连续重复三次的列表的副本
- java - SpringBoot 测试配置
- java - @NotNull 约束在 Spring Boot 中不起作用
- python - 将 Lasagne 转换为 Keras 代码 (CNN -> LSTM)
- laravel - MVC/PHP 我在哪里放置发出请求的代码?