作者darklimit ()
看板Python
标题[问题] 爬虫相关的疑问
时间Tue Aug 20 19:04:00 2013
之前有写了一个爬yahoo字典的而且确认没问题
今天重新跑发现很奇怪的问题
程式码如下
from bs4 import BeautifulSoup
req = urllib2.Request("
http://tw.dictionary.yahoo.com/dictionary?p=good")
html = urllib2.urlopen(req)
htmls = html.read()
html.close
soup = BeautifulSoup(htmls) #到这一行就会出错
以下内容是错误讯息
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
soup = BeautifulSoup(html)
File "C:\Python26\lib\site-packages\bs4\__init__.py", line 168, in __init__
self._feed()
File "C:\Python26\lib\site-packages\bs4\__init__.py", line 181, in _feed
self.builder.feed(self.markup)
File "C:\Python26\lib\site-packages\bs4\builder\_lxml.py", line 72, in feed
self.parser.close()
File "parser.pxi", line 1110, in lxml.etree._FeedParser.close
(src/lxml/lxml.etree.c:73063)
XMLSyntaxError: no element found
想请问是出了什麽错误?
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.135.114.19
1F:→ grapherd:html tag可能有问题, lxml下fromstring报错, HTML没问题 08/20 20:02
2F:→ qwertmn:我用2.7跑正常 08/21 00:07
3F:→ darklimit:恩,有找到了,yahoo那边把tag改掉了 08/21 08:29
4F:→ darklimit:所以导致後面tag有问题,^^谢谢 08/21 08:30