ランニング日誌サイトを運営しています。
ジョグナビ
節約テクニック
No1:家族(妻、子供など)名義で優待銘柄を買おう
No2:還元率の高いクレジットカードは
No3:エンジンオイルはエコオイルにしよう
No4:エコタイヤは性能と値段と相談
パンつくり
No1:小麦粉の配合
No2:日清カメリヤはどうなの
ジョグナビ
節約テクニック
No1:家族(妻、子供など)名義で優待銘柄を買おう
No2:還元率の高いクレジットカードは
No3:エンジンオイルはエコオイルにしよう
No4:エコタイヤは性能と値段と相談
パンつくり
No1:小麦粉の配合
No2:日清カメリヤはどうなの
GAEで中古価格を取得したい。アマゾンからの情報がXPathで取得できない。いや、できた!
dom4jを使って情報を取得しようとしていますがうまくいかない。何が悪いのかよくわからないなぁ。。。
HashMap map = new HashMap ();
map.put( "a", "http://webservices.amazon.com/AWSECommerceService/2009-03-31");
DocumentFactory fac = DocumentFactory.getInstance();
fac.setXPathNamespaceURIs(map);
SAXReader reader = new SAXReader();
reader.setDocumentFactory(fac);
org.dom4j.Document doc = new SAXReader().read(new URL(requestUrl));
if (doc != null){
System.err.print("doc=" + doc.getStringValue());
}
Dom4jXPath xpath = new Dom4jXPath ("/a:itemlookupresponse/a:items/a:item/a:offersummary/a:totalused");
xpath.addNamespace("a", "http://webservices.amazon.com/AWSECommerceService/2009-03-31");
List list = xpath.selectNodes(doc);
Iterator ite = list.iterator();
if (ite.hasNext()){
org.dom4j.Node node = (org.dom4j.Node)ite.next();
result.append("totalused=");
result.append(node.getText());
result.append(",");
}
結局のところXPathの表現が小文字だったのがいけなかったようだ・・・
いかにソースを載せます。試行錯誤の連続でしたが、せどりツールの骨格はできました。
あとはタイトルをとってくるのをつくればもっと使いやすくなるかな。
HashMap map = new HashMap ();
map.put( "a", "http://webservices.amazon.com/AWSECommerceService/2009-03-31");
DocumentFactory fac = DocumentFactory.getInstance();
fac.setXPathNamespaceURIs(map);
SAXReader reader = new SAXReader();
reader.setDocumentFactory(fac);
org.dom4j.Document doc = new SAXReader().read(new URL(requestUrl));
if (doc != null){
System.err.print("doc=" + doc.getStringValue());
}
Dom4jXPath xpath = new Dom4jXPath ("/a:ItemLookupResponse/a:Items/a:Item/a:OfferSummary/a:TotalUsed");
xpath.addNamespace("a", "http://webservices.amazon.com/AWSECommerceService/2009-03-31");
List list = xpath.selectNodes(doc);
Iterator ite = list.iterator();
if (ite.hasNext()){
org.dom4j.Node node = (org.dom4j.Node)ite.next();
result.append("totalused=");
result.append(node.getText());
result.append(",");
}
xpath = new Dom4jXPath ("/a:ItemLookupResponse/a:Items/a:Item/a:OfferSummary/a:LowestUsedPrice/a:FormattedPrice");
xpath.addNamespace("a", "http://webservices.amazon.com/AWSECommerceService/2009-03-31");
list = xpath.selectNodes(doc);
ite = list.iterator();
if (ite.hasNext()){
org.dom4j.Node node = (org.dom4j.Node)ite.next();
result.append("price=");
result.append(node.getText());
}
HashMap
作ればわかる!Google App Engine for Javaプログラミング
- 作者: 中垣 健志
- 出版社/メーカー: 翔泳社
- 発売日: 2011/04/23
- メディア: 大型本
?????????
私には??????。
by harley (2011-07-21 13:15)
すみません、専門的すぎて・・・
by thick-beard (2011-07-22 01:57)