我正在编写一个解析网页的程序(我无权访问,所以我无法修改它)。
首先,我连接并使用 getContent() 来获取页面的 InputStream。那里没有问题。
但是在解析时:
public static int[] parseMoveGameList(InputStream is) throws ParserConfigurationException, IOException, SAXException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.parse(is);
/*...*/
}
这里 builder.parse 抛出:
org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 64; The system identifier must begin with either a single or double quote character.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:253)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:288)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
at cs.ualberta.lgadapter.LGAdapter.parseMoveGameList(LGAdapter.java:78)
...
我正在解析(但无法更改)的页面看起来像
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html>
<head>
<META http-equiv="Expires" content="0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<!-- ... -->
</head>
<body>
<!-- ... -->
</body>
</html>
我怎样才能克服这个异常?