这里我只收到关于python的问题,我发现的工具大多是用于python的,所以新的问题是:我需要使用XPath从一个HTML站点查询一些东西。
我的当前代码如下:
URL url = new URL("http://somesite.com");
connection = (HttpURLConnection) url.openConnection();
connection.connect();
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(new InputSource(connection.getInputStream()));
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile("//span[@class='a-class']");
String price = (String) expr.evaluate(doc, XPathConstants.STRING);问题是,页面被破坏了,或者XPath有一些问题需要阅读:
致命错误:4:254:实体名称必须紧跟实体引用中的'&‘。 org.xml.sax.SAXParseException;lineNumber: 4;columnNumber: 254;实体名称必须紧跟实体引用中的'&‘。 在com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:251) 在com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:300)
有什么工具可以更好地阅读html网站吗?还是我应该在页面上使用Regex?
发布于 2013-04-09 07:43:20
有什么工具可以更好地阅读html网站吗?
人们对汤汁评价很高。
https://stackoverflow.com/questions/15896097
复制相似问题