Digikey部分价格python脚本
我试图写一个脚本来搜索digikey.com上的一个部件,并返回每个部件的价格折扣。我有困难,但打开网址。我看过其他类似的脚本,这就是我所想到的,但是我在BeautifulSoup中遇到了错误。我使用的是Python2.7,运行的是Ubuntu13.04Digikey部分价格python脚本,python,web,screen-scraping,Python,Web,Screen Scraping,我试图写一个脚本来搜索digikey.com上的一个部件,并返回每个部件的价格折扣。我有困难,但打开网址。我看过其他类似的脚本,这就是我所想到的,但是我在BeautifulSoup中遇到了错误。我使用的是Python2.7,运行的是Ubuntu13.04 #!/usr/bin/python # This script will find the page of a part and return the price # break information import BeautifulS
#!/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
回溯(最近一次呼叫最后一次):
文件“DigiKeyPrice.py”,第17行,在
汤=美汤(第页)
TypeError:“模块”对象不可调用
另外,我对python有点陌生,但任何帮助都将不胜感激
谢谢更换:
import BeautifulSoup
与:
另外,响应
变量未定义,请替换:
soup = BeautifulSoup(response)
与:
啊。。。我知道我忘了改变那个变量,我试着离开一些其他的例子。但是我想如果我只是导入BeautifulSoup,它就会导入整个模块。我错了吗?是的,但是你需要
beautifulsou
模块中的beautifulsou
类。谢谢你,这正是我的问题所在。我想我已经读到,我可以从BeautifulSoup导入所有内容,但我现在看到了我的问题所在,这也解释了为什么我会出现错误。
soup = BeautifulSoup(response)
soup = BeautifulSoup(page)