去哪儿网手机版机票数据
目录
携程手机版国内机票数据
携程手机版国际机票数据
携程网页版国内机票数据
携程网页版国际机票数据
去哪儿网手机版机票数据
去哪儿网网页版机票数据
携程手机版机票数据添加代理
去哪儿网网页版机票数据添加代理
选型
请求参数中,有pre、_m_等,需要进行js破解,难度较大,尝试了两次失败了,换方式。使用selenium抓取网页数据。
首选需要下载chromedriver,根据chrome的版本进行选择。链接地址:http://chromedriver.storage.googleapis.com/index.html
如果选择的版本错误,运行的时候控制台也会打印正确的版本,重新下载替换即可。
概述
去哪儿网手机版机票查询的网址是https://m.flight.qunar.com/h5/flight/
本篇使用上海到北京的航线进行测试。
Java开发
引入包
<dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-java</artifactId></dependency><dependency><groupId>net.lightbody.bmp</groupId><artifactId>browsermob-core</artifactId><version>2.1.5</version></dependency><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version> 22.0</version></dependency><dependency><groupId>net.lightbody.bmp</groupId><artifactId>browsermob-legacy</artifactId><version>2.1.5</version></dependency>
其中,selenium-java的作用即为动态数据获取,其他三个的作用是为了作为代理,获取到网页上没有显示但是接口返回的数据(版本必须对应,否则运行会报错)。
请求配置
去哪儿网做了反爬虫判断,如果直接打开chrome会一直加载中,不出来数据,所以需要增加下option的配置。
System.setProperty("webdriver.chrome.driver", "chromedriver的完整路径名称");ChromeOptions option = new ChromeOptions();option.addArguments("disable-infobars");List<Object> list=new ArrayList<>();list.add("enable-automation");option.setExperimentalOption("excludeSwitches",list);option.addArguments("--disable-blink-features", "--disable-blink-features=AutomationControlled");
添加代理
此步骤可选,代理的作用是可以拦截到所有网络请求,这样接口有但是界面上没有显示的数据也就可以得到了。
BrowserMobProxy proxy = new BrowserMobProxyServer();proxy.start(0);proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);proxy.setHarCaptureTypes(CaptureType.RESPONSE_CONTENT);proxy.newHar("qunanr");Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);seleniumProxy.setHttpProxy("localhost:" + proxy.getPort());seleniumProxy.setSslProxy("localhost:" + proxy.getPort());proxy.addRequestFilter((request, contents, messageInfo) -> {System.out.println("这里拦截请求" + request.uri() + "###" + contents.getTextContents() + ">>>"+ request.headers().get("Cookie"));return null;});option.setProxy(seleniumProxy);option.setAcceptInsecureCerts(true);option.setExperimentalOption("useAutomationExtension", false);proxy.addResponseFilter((response, contents, messageInfo) -> {if (messageInfo.getUrl().contains("wbdflightlist")) {// 这个接口是机票列表详细信息,可解析后使用System.out.println(response.status() + ":" + response.headers().get("cookie") + ">>>"+ contents.getTextContents());}});
获取网页数据
String url = "https://m.flight.qunar.com/ncs/page/flightlist?depCity=%E4%B8%8A%E6%B5%B7&arrCity=%E5%8C%97%E4%BA%AC&goDate=2022-01-01&from=touch_index_search&child=0&baby=0&cabinType=0";WebDriver webDriver = new ChromeDriver(option);webDriver.get(url);List<WebElement> resultElements = webDriver.findElements(By.className("list-content")).get(0).findElements(By.tagName("li"));for (int i = 0; i < resultElements.size(); i++) {System.out.println((i+1) + "\n" + resultElements.get(i).getText());System.out.println();}proxy.stop();webDriver.quit();
打印内容大概如下,可以根据需要调整标签数据。
19
15:00
虹桥T2
2时15分
17:15
首都T2
东航MU5115 波音777(大)
500
经济舱2.8折20
15:30
虹桥T2
2时30分
18:00
首都T2
东航MU5161 空客330(大)
500
经济舱2.8折21
16:00
虹桥T2
2时20分
18:20
首都T2
东航MU5117 波音777(大)
500
经济舱2.8折22
16:15
浦东T2
2时25分
18:40
首都T3
国航CA1884 空客330(大)
500
经济舱2.8折23
17:00
虹桥T2
2时15分
19:15
首都T2
东航MU5119 空客330(大)
500
经济舱2.8折24
18:00
虹桥T2
2时15分
20:15
首都T2
东航MU5121 波音777(大)
500
经济舱2.8折25
19:00
虹桥T2
2时20分
21:20
首都T2
东航MU5123 空客330(大)
500
经济舱2.8折
其他
移动端的如果点击加载更多,会出现输入手机号验证码登录的页面,暂时没有想到处理该问题的方法。
// 点击加载更多
webDriver.findElements(By.className("list-getmore")).get(0).click();
// 给某个控件赋值,格式是 webDriver.findElements(By.className("list-getmore")).get(0).sendKeys("数值");)
完整代码
public static void main(String[] args) {System.setProperty("webdriver.chrome.driver", "/Users/admin/Documents/workspace/chromedriver");ChromeOptions option = new ChromeOptions();option.addArguments("disable-infobars");List<Object> list = new ArrayList<>();list.add("enable-automation");option.setExperimentalOption("excludeSwitches", list);option.addArguments("--disable-blink-features", "--disable-blink-features=AutomationControlled");BrowserMobProxy proxy = new BrowserMobProxyServer();proxy.start(0);proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);proxy.setHarCaptureTypes(CaptureType.RESPONSE_CONTENT);proxy.newHar("qunanr");Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);seleniumProxy.setHttpProxy("localhost:" + proxy.getPort());seleniumProxy.setSslProxy("localhost:" + proxy.getPort());proxy.addRequestFilter((request, contents, messageInfo) -> {
// System.out.println("这里拦截请求" + request.uri() + "###" + contents.getTextContents() + ">>>"
// + request.headers().get("Cookie"));return null;});option.setProxy(seleniumProxy);option.setAcceptInsecureCerts(true);option.setExperimentalOption("useAutomationExtension", false);proxy.addResponseFilter((response, contents, messageInfo) -> {if (messageInfo.getUrl().contains("wbdflightlist")) {// 这个接口是机票列表详细信息,可解析后使用
// System.out.println(response.status() + ":" + response.headers().get("cookie") + ">>>"
// + contents.getTextContents());}});String url = "https://m.flight.qunar.com/ncs/page/flightlist?depCity=%E4%B8%8A%E6%B5%B7&arrCity=%E5%8C%97%E4%BA%AC&goDate=2022-01-01&from=touch_index_search&child=0&baby=0&cabinType=0";WebDriver webDriver = new ChromeDriver(option);webDriver.get(url);List<WebElement> resultElements = webDriver.findElements(By.className("list-content")).get(0).findElements(By.tagName("li"));for (int i = 0; i < resultElements.size(); i++) {System.out.println((i+1) + "\n" + resultElements.get(i).getText());System.out.println();}proxy.stop();webDriver.quit();}
去哪儿网手机版机票数据相关推荐
- 去哪儿网网页版机票数据
目录 携程手机版国内机票数据 携程手机版国际机票数据 携程网页版国内机票数据 携程网页版国际机票数据 去哪儿网手机版机票数据 去哪儿网网页版机票数据 携程手机版机票数据添加代理 去哪儿网网页版机票数据 ...
- 去哪儿网网页版机票数据添加代理
目录 携程手机版国内机票数据 携程手机版国际机票数据 携程网页版国内机票数据 携程网页版国际机票数据 去哪儿网手机版机票数据 去哪儿网网页版机票数据 携程手机版机票数据添加代理 去哪儿网网页版机票数据 ...
- 携程手机版机票数据添加代理
目录 携程手机版国内机票数据 携程手机版国际机票数据 携程网页版国内机票数据 携程网页版国际机票数据 去哪儿网手机版机票数据 去哪儿网网页版机票数据 携程手机版机票数据添加代理 去哪儿网网页版机票数据 ...
- qq邮箱电脑版登录入口_青骄第二课堂学生平台登录入口,青骄第二课堂登录入口(官网手机版入口:https://m.2class.com/)...
青骄第二课堂学生平台登录入口,青骄第二课堂登录入口(官网手机版入口:https://m.2-class.com/) ---------------------------------- ...
- 3手机版怎么换行_全国青少年普法网手机怎么登录 教育部普法网手机版登录入口:http://qspfw.moe.gov.cn...
阅读本文前,请您先点击上面的"蓝色字体",再点击"关注",这样您就可以继续免费收到文章了.每天都有分享,完全是免费订阅,请放心关注. 注:本文转载自网络,不代表 ...
- 3手机版怎么换行_全国青少年普法网手机怎么登录 教育部普法网手机版登录入口https://user.qspfw.com/page/login...
阅读本文前,请您先点击上面的"蓝色字体",再点击"关注",这样您就可以继续免费收到文章了.每天都会有分享,都是免费订阅,请您放心关注.注:本文转载自网络,不代表 ...
- 华为鸿蒙手机beta版,华为鸿蒙OSBeta版-华为鸿蒙OSBeta版官网手机版预约 -优盘手机站...
华为鸿蒙OSBeta版是一款全新操作系统的更新发布,采用了全新的艺术主题,主屏幕底部使用了非常动感的光效,一镜到底的动效,让大家的视觉体验更加的酷炫,多屏协同,使用的时候,更加的简单方便,许多的应用都 ...
- 我的世界手机版javaui材质包_45woool传奇世界网手机版下载-45woool传奇世界手游全部版本合集...
45woool传奇世界网手机版等级:7.12020-11-10166.8MB简体中文下载推荐理由:45woool传奇世界网手机版,是一款支持三端互通的玩法的高人气传奇手游,也是一款更适合平民玩家的长期 ...
- 飞猪、去哪儿网被列入大数据“杀熟”名单,超50%的人遭遇过被“杀熟”
自2018年以来,大数据"杀熟"问题就时常引起公众或相关媒体的热议.不过一直都停留在主观猜测和表面宣泄层面.今年的3月27日上午,随着北京市消协召开大数据"杀熟" ...
最新文章
- Jsp实现在线影院售票系统
- Redis基础知识之—— hset 和hsetnx 的区别
- 三分钟Docker-推送本地镜像到仓库
- 车站广播系统采用计算机,公共广播系统
- gifcam使用缩小内存_Vuex3.1.1更新:支持jsDelivr,修复内存泄漏
- mysql xtrabackup安装与原理
- 牛客网在线编程:公共字符
- WCF技术内幕之面向服务
- 2017-2018-2 1723《程序设计与数据结构》实验四 实验五 课程总结 总结
- 有没有人被向量空间、内积空间、欧式空间、希尔伯特空间、巴拿赫空间概念折磨的?
- javaweb JAVA JSP水费管理系统JSP电费管理系统JSP缴费管理系统JSP水费缴费系统JSP水电费管理
- 鲁棒优化入门(4)-两阶段鲁棒优化及行列生成算法(CCG)超详细讲解(附matlab代码)
- 中国移动明确5G商用时间表
- The request was rejected because the URL contained a potentially malicious String “//“
- 二级c语言大题100道,2013二级c语言真题100道
- 基于VRML的虚拟校园漫游系统源代码
- 刷新率属于计算机的显示性能指标吗,显示器性能参数的含义
- IDEA连接mysql保姆级教学
- C++程序设计原理与实践电子书pdf下载
- 【每日早报】2019/09/10