2010-06-04 81 views
0

我正在寫一個小型網站設計師到make my local airport site work with standard HTMLPython:機械化和BeautifulSoup不在共享主機上工作

在我的本地計算機上,我使用Python的mechanizeBeautifulSoup軟件包來抓取和分析網站內容,並且一切看起來都很順利。我已經通過apt-get安裝了這些軟件包。

在我的共享主機的網站(在DreamHost)我已經下載了.tar.gz文件,提取的包,改名目錄(例如,從BeautifulSoup-3.1.0.tar.gzBeautifulSoup),並試圖運行命令。

我與BeautifulSoup有一個奇怪的錯誤;我不知道它是關於Dreamhost上的Python舊版本,關於目錄名稱還是其他原因。

[sanjose]$ python 
Python 2.4.4 (#2, Jan 24 2010, 11:50:13) 
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> from BeautifulSoup import BeautifulSoup       
>>> import mechanize             
>>> url='http://www.iaa.gov.il/Rashat/he-IL/Airports/BenGurion/informationForTravelers/OnlineFlights.aspx?flightsType=arr' 
>>> br=mechanize.Browser()                         
>>> br.addheaders = [('User-agent', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)')]         
>>> r=br.open(url) 
>>> html=r.read() 
>>> type(html) 
<type 'str'> 

我這樣做是爲了表明輸入確實是一個字符串。現在讓我們運行在我的本地計算機上運行的命令:

>>> soup = BeautifulSoup.BeautifulSoup(html) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in ? 
    File "/home/adamatan/matan.name/natbug/BeautifulSoup/BeautifulSoup.py", line 1493, in __init__ 
    BeautifulStoneSoup.__init__(self, *args, **kwargs) 
    File "/home/adamatan/matan.name/natbug/BeautifulSoup/BeautifulSoup.py", line 1224, in __init__ 
    self._feed(isHTML=isHTML) 
    File "/home/adamatan/matan.name/natbug/BeautifulSoup/BeautifulSoup.py", line 1257, in _feed 
    self.builder.feed(markup) 
    File "/usr/lib/python2.4/HTMLParser.py", line 108, in feed 
    self.goahead(0) 
    File "/usr/lib/python2.4/HTMLParser.py", line 148, in goahead 
    k = self.parse_starttag(i) 
    File "/usr/lib/python2.4/HTMLParser.py", line 268, in parse_starttag 
    self.handle_starttag(tag, attrs) 
    File "/home/adamatan/matan.name/natbug/BeautifulSoup/BeautifulSoup.py", line 1011, in handle_starttag 
    self.soup.unknown_starttag(name, attrs) 
    File "/home/adamatan/matan.name/natbug/BeautifulSoup/BeautifulSoup.py", line 1408, in unknown_starttag 
    tag = Tag(self, name, attrs, self.currentTag, self.previous) 
    File "/home/adamatan/matan.name/natbug/BeautifulSoup/BeautifulSoup.py", line 525, in __init__ 
    self.attrs = map(convert, self.attrs) 
    File "/home/adamatan/matan.name/natbug/BeautifulSoup/BeautifulSoup.py", line 524, in <lambda> 
    val)) 
    File "/usr/lib/python2.4/sre.py", line 142, in sub 
    return _compile(pattern, 0).sub(repl, string, count) 
TypeError: expected string or buffer 

任何想法?

Adam

回答

3

您正在使用適用於Python 3.x的BeautifulSoup版本3.1.0。使用3.0版本的BeautifulSoup for Python 2.x.

+0

+1你可能在這裏節省了我幾個小時。謝謝。 – 2010-06-04 22:48:02