package com.hym.io;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Node;
public class GetNewBKPlayerPhoto {
private final static String PLAYER_BET_ID_PATH = "E:\\work\\2014\\basketball\\20140116_photo\\PlayerBetId2.txt";
private final static String PLAYER_XML_PATH = "E:\\work\\2014\\basketball\\20140116_photo\\LqPlayer_xml.xml";
private final static String PLAYER_NO_PHOTO_PATH = "E:\\work\\2014\\basketball\\20140116_photo\\noPhoto3.txt";
private final static String localPath = "E:\\work\\2014\\basketball\\20140116_photo\\bkPlayerPhoto3";
public static void main(String[] args) {
System.out.println("downloaded begin ...... ");
GetNewBKPlayerPhoto getPhoto = new GetNewBKPlayerPhoto();
List<String> noPhotoList = getPhoto.downLoadPhoto();
try {
FileUtils.writeLines(new File(PLAYER_NO_PHOTO_PATH), noPhotoList);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("downloaded end ...... ");
}
public List<String> getNewPlayerBetId() {
try {
//File file = new File(PLAYER_BET_ID_PATH);
//List<String> betIds = FileUtils.readLines(file);
List<String> betIds = new ArrayList<String>();
for (int i = 3791; i<= 4013; i++) {
betIds.add(String.valueOf(i));
}
return betIds;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public Map<String, String> getBetIdPhotoMap() {
List<String> playerBetIdList = getNewPlayerBetId();
Map<String, String> betIdPhotoMap = new HashMap<String, String>();
String xml;
try {
xml = FileUtils
.readFileToString(new File(PLAYER_XML_PATH), "utf-8");
Element root = getRoot(xml);
for (String betId : playerBetIdList) {
String photo = getNodeAttribute(root, "i", "Photo", "id", betId);
betIdPhotoMap.put(betId, photo);
}
} catch (IOException e) {
e.printStackTrace();
}
return betIdPhotoMap;
}
public List<String> downLoadPhoto() {
List<String> noPhotoList = new ArrayList<String>();
Map<String, String> betIdPhotoMap = getBetIdPhotoMap();
if (betIdPhotoMap != null && !betIdPhotoMap.isEmpty()) {
Set<String> keySet = betIdPhotoMap.keySet();
Iterator<String> iter = keySet.iterator();
while (iter.hasNext()) {
String betId = iter.next();
String photo = betIdPhotoMap.get(betId);
if (StringUtils.isEmpty(photo) || photo.indexOf("no") > -1) {
noPhotoList.add(betId);
continue;
}
downBKPlayerPhoto(betId, photo);
System.out.println("downloaded betId = " + betId + ", photo = " + photo);
}
}
return noPhotoList;
}
private Element getRoot(String xml) {
try {
Document doc = DocumentHelper.parseText(xml);
Element root = doc.getRootElement();
return root;
} catch (DocumentException e) {
e.printStackTrace();
}
return null;
}
public String getNodeAttribute(Element root, String nodeName,
String attrName, String key, String value) {
List<Node> nodes = root.selectNodes("//" + nodeName + "[" + key + "='"
+ value + "']");
if (nodes == null || nodes.isEmpty()) {
return null;
}
return nodes.get(0).valueOf(attrName);
}
public void downBKPlayerPhoto(String betId, String photo) {
String webSite = "http://nba.xxx.com";
// 一个一个下载照片,并写入本地
String suffix = photo.substring(photo.lastIndexOf("."));
URL url;
try {
url = new URL(webSite + photo);
File file = new File(localPath + "\\" + betId + suffix);
FileUtils.copyURLToFile(url, file);
} catch (Exception e) {
e.printStackTrace();
}
}
}
分享到:
相关推荐
官方离线安装包,亲测可用
BIT-101 XPath Query Tool XML查询工具
《XML》实验任务书 【3】 XPath & XSLT [实验目的] 1、学习如何使用XMLSPY集成开发环境执行XPath查询、以及XSLT的数据转换。 2、理解XPath的类型系统和序列类型等相关概念,掌握XPath表达式语法和执行语义,能够...
1. 更换默认的xpath库 除了ie,其他主要浏览器都是内置对xpath的支持的,但ie不行,所以selenium 使用了javascript库,默认使用的是ajaxslt,这个会比较慢,可以换成 javascript-xpath, 虽然比firefox还是慢...
此算法实现是基于Xpath的xml文件查询,只要输入Xpath路径(全路径)就能返回目标节点信息,同时也支持数据的更新设置。
xpath读取XML节点 用jdom包
离线安装包,亲测可用
uiautomatorviewer 的增强版,能定位控件 xpath 路径,便于后续项目使用 用法: 将压缩包中的 jar 包替换掉原 uiautomatorviewer 的 jar 包,原 jar 包一般在 sdk\tools\lib 中,注意:jar 包名称需更改为原 jar 包...
XML应用开发(软件品牌)-1期 5.3案例分析-使用XPath路径导航.doc 学习资料 复习资料 教学资源
wicked-good-xpath, 纯JS实现DOM级别 3 XPath规范 很好的XPath Wicked XPath是谷歌编写的DOM级别 3 XPath规范的纯JavaScript实现。 它为每个浏览器中的HTML文档启用XPath评估。 我们相信它是JavaScript中最快的XPath...
使用xpath读取xml中的数据
CSS、DHTML、XMLDOM、T-SQL、XPath、正则表达式等CHM格式学习文档
Xpath 解析xml 文件,并转化为csv文件
commons-lang3-3.3.2、jsoup-1.13.1和JsoupXpath-0.3.2,要是实现JsoupXpath必须要加载依赖包commons-lang3-3.3.2、jsoup-1.13.1。
XPath解析xml的例子;mybatis入门之xpath解析xml;至少xpath入门
之前找了好多感觉和自己的需求不太一样,这个可以根据Xpath解析出来xml里所有的信息,十分好用 举个例子 xmlPath = "E://upload/xml/1580242.163.xml"; XPathUtil util = XPathUtil.newInstance(xmlPath); Product ...
1.可以根据传入的xpath,生成xml,例如:a/b/c : <a><b><c></c></b></a> 2.可以将指定xml字符串添加指定节点 3.xmldocument2String 4.支持属性操作 看到网上几乎没有这样的例子,贡献一下,中国的软件太需要贡献了...
Dom,Sax,Xpath解析XML实例,有源码,实例。简单易用,直接可用
实用的JSTL想要的可以下载!!!解压就可以使用