python读取路径太长_python – OSError:[Errno 36]文件名太长:

  • Post author:
  • Post category:python


我需要将网页转换为

XML(使用

Python 3.4.3).如果我将URL的内容写入文件,那么我可以完美地阅读和解析它,但如果我尝试直接从网页上读取,我的终端中会出现以下错误:

File “./AnimeXML.py”, line 22, in

xml = ElementTree.parse (xmlData)

File “/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/xml/etree/ElementTree.py”, line 1187, in parse

tree.parse(source, parser)

File “/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/xml/etree/ElementTree.py”, line 587, in parse

source = open(source, “rb”)

OSError: [Errno 36] File name too long:

我的python代码:

# AnimeXML.py

#! /usr/bin/Python

# Import xml parser.

import xml.etree.ElementTree as ElementTree

# XML to parse.

sampleUrl = “http://cdn.animenewsnetwork.com/encyclopedia/api.xml?anime=16989”

# Read the xml as a file.

content = urlopen (sampleUrl)

# XML content is stored here to start working on it.