我正在尝试编写一个脚本来搜索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的新手,但任何帮助都会受到赞赏。
由于
答案 0 :(得分:1)
替换:
import BeautifulSoup
使用:
from BeautifulSoup import BeautifulSoup
另外,response
变量未定义,替换为:
soup = BeautifulSoup(response)
使用:
soup = BeautifulSoup(page)