4

我正在尝试编写一个脚本来搜索 digikey.com 的一部分并返回每个部分的价格中断。我在打开网址时遇到了麻烦。我查看了其他类似的脚本,这就是我想出的,但我收到 BeautifulSoup 错误。我正在使用 Python 2.7 并运行 Ubuntu 13.04。

#!/usr/bin/python

# This script will find the page of a part and return the price 
# break information

import BeautifulSoup
import urllib2


# Create Url to read
Digikey_url = 'http://digikey.com/scripts/DkSearch/dksus.dll?Detail&name='
partNum = '458-1003-ND'
url=Digikey_url+partNum

# Create BeautifulSoup Object 
page = urllib2.urlopen(url)
soup = BeautifulSoup(response)


# Close Page
page.close()

这是我得到的错误:

Traceback (most recent call last):
  File "DigiKeyPrice.py", line 17, in <module>
    soup = BeautifulSoup(page)
TypeError: 'module' object is not callable

我也是python的新手,但任何帮助将不胜感激。

谢谢

4

1 回答 1

1

代替:

import BeautifulSoup

和:

from BeautifulSoup import BeautifulSoup

另外,response未定义变量,请替换:

soup = BeautifulSoup(response)

和:

soup = BeautifulSoup(page)
于 2013-07-23T12:34:45.417 回答