java爬取网页源代码,解析
来源:互联网 发布:纸模软件apk 编辑:程序博客网 时间:2024/06/04 18:18
1.搜索词的地址采用模拟地址方法(通过分析搜索引擎的参数得到,如百度),然后将搜索词加到模拟的地址中。
2.函数的输入参数是模拟地址。
String query = URLEncoder.encode("何青松", "UTF-8");String url="http://www.baidu.com/s?wd="+query+"&pn="+p*10+"&tn=baiduhome_pg&ie=utf-8"public void MakeQuery(String domain) { try { HttpClient httpClient = new HttpClient(); GetMethod getMethod = new GetMethod(domain); //System.out.println("*************************************************************"); //System.out.println(getMethod); try{ httpClient.executeMethod(getMethod); }catch(Exception e){ System.out.println("网络问题"); } getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); int statusCode = httpClient.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + getMethod.getStatusLine()); } byte[] responseBody = getMethod.getResponseBody(); //System.out.println("*************************************************************"); //System.out.println(responseBody); String response = new String(responseBody, "UTF-8"); //System.out.println("*************************************************************"); //System.out.println(response); //Jsoup解析html Document doc=Jsoup.parse(response); //System.out.println("*************************************************************"); //System.out.println(doc); Elements contents=doc.getElementsByClass("f"); for(Element content:contents){ Element links = content.getElementsByTag("a").first(); String linkHref = links.attr("href");//链接 String linkText = links.text();//摘要 FoursearchZH.map.put(linkHref, linkText); System.out.println("------------------"); System.out.println(linkHref); System.out.println(linkText); } } catch (Exception e) { System.err.println("Something went wrong..."); e.printStackTrace(); } }
- java爬取网页源代码,解析
- java之爬虫:爬取网页源代码
- HttpClient爬取网页源代码
- 用Java爬取网页
- JAVA爬取网页内容
- Java爬取网页图片
- JAVA爬取网页内容
- 如何解析网页源代码
- python爬虫入门篇------爬取网页源代码
- python解析百度网页源代码:取搜索引擎返回的前page_num*10个链接的url
- java Jsoup实现新闻网页的爬取,标题,正文,图片,新闻时间,网页链接的解析示例
- java爬取网页内容 简单例子
- 基于Java的Heritrix爬取网页
- java爬取网页内容 简单例子
- java 爬取网页页面内容
- java Jsoup 爬取网页数据
- 使用JAVA爬取网页图片
- java简单爬取网页内容实例
- CORTEX-崭新的ARMv7内核
- java生成缩略图
- windows7英文版,变为中文版
- iphone游戏开发之cocos2d( 十一 )使用CCSpriteBatchNode和纹理图册,提高精灵动画效率;
- web前端性能优化进阶路
- java爬取网页源代码,解析
- WPF学习总结和记录(二)内容控件
- KDE Gnome konsole
- GridLayoutFactory和GridDataFactory
- ping实现
- Android 实时视频采集—Camera预览采集
- 孤单还是对你最好的惩罚
- 从Android界面开发谈起
- [LeetCode] Text Justification