3

我试图读取的数据是 xml 格式。xml 声明前有一个空格。我无法编辑这部分,因为它被硬编码到数据源中。我只能从中读取。当在 IE 中输入 url 时,数据就会出现。在 Chrome/Firefox 中输入时,会显示错误,但可以从查看源查看数据。

python有没有办法像IE一样去掉这个空间或者忽略它?

(尝试strip()在很多地方添加)

或者有没有办法默认页面源(我认为 urlopen 已经这样做了)?

这是给出错误的行:

html = urlopen(address).read()

这是错误:

Traceback (most recent call last):
File "C:\Users\212311674\Desktop\Python Work\M10url.py", line 27, in <module>
  html = urlopen(address).read()
File "C:\Python33\lib\urllib\request.py", line 160, in urlopen
  return opener.open(url, data, timeout)
File "C:\Python33\lib\urllib\request.py", line 473, in open
  response = self._open(req, data)
File "C:\Python33\lib\urllib\request.py", line 491, in _open
  '_open', req)
File "C:\Python33\lib\urllib\request.py", line 451, in _call_chain
  result = func(*args)
File "C:\Python33\lib\urllib\request.py", line 1272, in http_open
  return self.do_open(http.client.HTTPConnection, req)
File "C:\Python33\lib\urllib\request.py", line 1257, in do_open
  r = h.getresponse()
File "C:\Python33\lib\http\client.py", line 1131, in getresponse
  response.begin()
File "C:\Python33\lib\http\client.py", line 354, in begin
  version, status, reason = self._read_status()
File "C:\Python33\lib\http\client.py", line 336, in _read_status
  raise BadStatusLine(line)
http.client.BadStatusLine:  <?xml version="1.0"?><controller_history_cnd>
4

0 回答 0