擅长:python、mysql、java
<p><a href="http://parsers" rel="nofollow">^{<cd1>}</a>设计为从<a href="https://docs.python.org/2/glossary.html#term-file-object" rel="nofollow"><strong>file-like objects</strong></a>读取。你知道吗</p>
<p>但是在这两种情况下都传递一个字符串-<code>pinnacle_feed_basketball.xml</code>字符串和<code>responseData</code>,这也是一个字符串。你知道吗</p>
<p>在第一种情况下,应该是:</p>
<pre><code>with open("pinnacle_feed_basketball.xml") as f:
tree = etree.parse(f)
</code></pre>
<p>在第二种情况下:</p>
<pre><code>root = etree.fromstring(responseData) # note that you are not getting an "ElementTree" object here
</code></pre>
<hr/>
<p>仅供参考,<code>urllib2.urlopen(req)</code>也是一个类似文件的对象:</p>
<pre><code>tree = etree.parse(urllib2.urlopen(req))
</code></pre>