java 爬虫报错 ,网站meta不匹配如何解析?

Document document;

ReponseBody =mingspider.getrequestdata("https://gongshang.mingluji.com/beijing/diqu/%E4%B8%9C%E5%9F%8E");

System.out.println(ReponseBody);

document = (Document) DocumentHelper.parseText(ReponseBody);

org.dom4j.DocumentException: Error on line 86 of document  : 元素类型 "meta" 必须由匹配的结束标记 "</meta>" 终止。 Nested exception: 元素类型 "meta" 必须由匹配的结束标记 "</meta>" 终止。

at org.dom4j.io.SAXReader.read(SAXReader.java:482)

at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:278)

at main.Main.main(Main.java:24)

Nested exception:

org.xml.sax.SAXParseException; lineNumber: 86; columnNumber: 3; 元素类型 "meta" 必须由匹配的结束标记 "</meta>" 终止。

at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)

at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)

at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)

at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)

at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1472)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1749)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2967)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)

at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)

at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)

at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)

at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)

at org.dom4j.io.SAXReader.read(SAXReader.java:465)

at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:278)

at main.Main.main(Main.java:24)

Nested exception: org.xml.sax.SAXParseException; lineNumber: 86; columnNumber: 3; 元素类型 "meta" 必须由匹配的结束标记 "</meta>" 终止。

at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)

at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)

at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)

at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)

at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1472)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1749)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2967)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)

at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)

at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)

at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)

at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)

at org.dom4j.io.SAXReader.read(SAXReader.java:465)

at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:278)

at main.Main.main(Main.java:24)

回答

如果从报错来看,那就是你要解析的xml不符合要求呗,原因也说明白了,meta标签没有被关闭或者是说没有结束标签

你从网页下载下来的应该是一个HTML,而HTML并不严格要求是否一定要有结束标签,但是你现在是用dom4j按照xml进行解析的,那就得按照xml的要求来

因为不清楚mingspider.getrequestdata这里面到底做了啥,也不排除你在其中做了一些什么骚操作。

不过这个网址https://gongshang.mingluji.com/beijing/diqu/%E4%B8%9C%E5%9F%8E,去看了一下,本身它貌似就是只有一个meta标签确实没有被关闭
java 爬虫报错 ,网站meta不匹配如何解析?

至于mingspider.getrequestdata里有底有没有其他操作不知道,只能说从现在获取到的信息得出以上的判断吧,希望能有所帮助
`

以上是 java 爬虫报错 ,网站meta不匹配如何解析? 的全部内容, 来源链接: utcz.com/a/63243.html

回到顶部