AlchemyAPI Python SDK错误

2024-06-16 12:43:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用alchemyapython0.7sdk。但是,当我在其中运行一个方法时,例如URLGetText(url)

我得到这个错误:

    nodes = etree.fromstring(result).xpath(xpathQuery)
  File "lxml.etree.pyx", line 2743, in lxml.etree.fromstring (src/lxml/lxml.etree.c:52665)
  File "parser.pxi", line 1573, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:79932)
  File "parser.pxi", line 1452, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:78774)
  File "parser.pxi", line 960, in lxml.etree._BaseParser._parseDoc (src/lxml/lxml.etree.c:75389)
  File "parser.pxi", line 564, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:71739)
  File "parser.pxi", line 645, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:72614)
  File "parser.pxi", line 585, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:71955)
lxml.etree.XMLSyntaxError: AttValue: " or ' expected, line 19, column 11

这来自于以下代码:

^{pr2}$

有人知道出什么问题了吗?在

谢谢你

丹尼尔·克肖


Tags: 方法insrcparserurl错误linesdk
1条回答
网友
1楼 · 发布于 2024-06-16 12:43:55

我查看了Python urllib文档,发现了以下页面:

http://docs.python.org/library/urllib.html#high-level-interface

其中包含有关urllib.urlopen()返回的filehandle对象的警告:

One caveat: the read() method, if the size argument is omitted or negative, may not read until the end of the data stream; there is no good way to determine that the entire stream from a socket has been read in the general case.

我认为在使用etree.fromstring()API解析文件之前,您应该确保以Python字符串的形式获取文件的全部内容。比如:

result = ''
while (1):
    next = handle.read()
    if not next: 
        break
    result += next

相关问题 更多 >