不能';t在python 2.7和selenium中导入'beautifulSoup'
我正在尝试导入不能';t在python 2.7和selenium中导入'beautifulSoup',python,selenium,beautifulsoup,Python,Selenium,Beautifulsoup,我正在尝试导入beautifulSoup,但出现错误。请告诉我原因,或指导我解决相同问题 Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Arup Rakshit>python 'python' is not recognized as an internal or external command, operable
beautifulSoup
,但出现错误。请告诉我原因,或指导我解决相同问题
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Arup Rakshit>python
'python' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\Arup Rakshit>ipython
'ipython' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\Arup Rakshit>cd..
C:\Users>cd..
C:\>cd Python27
C:\Python27>cd C:\Python27\selenv\Scripts
C:\Python27\selenv\Scripts>my_selenium_script.py
hello
C:\Python27\selenv\Scripts>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib import urlopen
>>> from beautifulSoup import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named beautifulSoup
>>>
Microsoft Windows[版本6.1.7600]
版权所有(c)2009微软公司。版权所有。
C:\Users\Arup Rakshit>python
“python”未被识别为内部或外部命令,
可操作的程序或批处理文件。
C:\Users\Arup Rakshit>ipython
“ipython”未被识别为内部或外部命令,
可操作的程序或批处理文件。
C:\Users\Arup Rakshit>cd。。
C:\Users>cd。。
C:\>cd蟒蛇27
C:\Python27>cd C:\Python27\selenv\Scripts
C:\Python27\selenv\Scripts>my\u selenium\u script.py
你好
C:\Python27\selenv\Scripts>python
Python 2.7.3(默认值,2012年4月10日23:31:26)[MSC v.1500 32位(英特尔)]关于win
32
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>从urllib导入urlopen
>>>从beautifulSoup导入beautifulSoup
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:没有名为beautifulSoup的模块
>>>
编辑
>>> from BeautifulSoup import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named BeautifulSoup
>>>
from bs4 import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named bs4
>>从BeautifulSoup导入BeautifulSoup
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:没有名为BeautifulSoup的模块
>>>
从bs4导入BeautifulSoup
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:没有名为bs4的模块
>
EDIT1
>>> from urllib import urlopen
>>> from bs4 import BeautifulSoup
>>> source = BeautifulSoup(urlopen(url))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'url' is not defined
>>> source = BeautifulSoup(urlopen(https://demo.aravo.com))
File "<stdin>", line 1
source = BeautifulSoup(urlopen(https://demo.aravo.com))
^
SyntaxError: invalid syntax
>>> from urllib import urlopen
>>> from bs4 import BeautifulSoup
>>> source = BeautifulSoup(urlopen(https://demo.aravo.com/))
File "<stdin>", line 1
source = BeautifulSoup(urlopen(https://demo.aravo.com/))
^
SyntaxError: invalid syntax
>>> source = BeautifulSoup(urlopen(demo.aravo.com/))
File "<stdin>", line 1
source = BeautifulSoup(urlopen(demo.aravo.com/))
^
SyntaxError: invalid syntax
>>> source = BeautifulSoup(urlopen(demo.aravo.com))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'demo' is not defined
>>>
>>从urllib导入urlopen
>>>从bs4导入BeautifulSoup
>>>source=BeautifulSoup(urlopen(url))
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
NameError:未定义名称“url”
>>>source=BeautifulSoup(urlopen(https://demo.aravo.com))
文件“”,第1行
source=BeautifulSoup(urlopen(https://demo.aravo.com))
^
SyntaxError:无效语法
>>>从urllib导入urlopen
>>>从bs4导入BeautifulSoup
>>>source=BeautifulSoup(urlopen(https://demo.aravo.com/))
文件“”,第1行
source=BeautifulSoup(urlopen(https://demo.aravo.com/))
^
SyntaxError:无效语法
>>>source=BeautifulSoup(urlopen(demo.aravo.com/)
文件“”,第1行
source=BeautifulSoup(urlopen(demo.aravo.com/)
^
SyntaxError:无效语法
>>>source=BeautifulSoup(urlopen(demo.aravo.com))
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
NameError:未定义名称“demo”
>>>
更新
C:\>cd C:\Python27\selenv\Scripts
C:\Python27\selenv\Scripts>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib import urlopen
>>> from bs4 import BeautifulSoup
>>> source = BeautifulSoup(urlopen("https://demo.aravo.com/"))
>>> tables = source.findAll('td')
>>> import csv
>>> writer = csv.writer(open('filename.csv','w'))
>>> writer.writerow(rows)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'rows' is not defined
>>>
C:\>cd C:\Python27\selenv\Scripts
C:\Python27\selenv\Scripts>python
Python 2.7.3(默认值,2012年4月10日23:31:26)[MSC v.1500 32位(英特尔)]关于win
32
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>从urllib导入urlopen
>>>从bs4导入BeautifulSoup
>>>source=beautifulsou(urlopen(“https://demo.aravo.com/"))
>>>tables=source.findAll('td')
>>>导入csv
>>>writer=csv.writer(打开('filename.csv','w'))
>>>writer.writerow(行)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
NameError:未定义名称“行”
>>>
谢谢,试着大写
BeautifulSoup
from BeautifulSoup import BeautifulSoup
如果您使用的是BS4:
from bs4 import BeautifulSoup
正如@poke明智地建议的那样,确保安装了
BeautifulSoup
是关键:)试试这个,它讨论了Windows上的BS安装:嗯。。。看起来Python还没有添加到PATH变量中。。。myu selinuim\u script.py
中发生了什么?@Benmyu selinuim\u script.py
向我提供输出hello
。我想没关系!如果两者都不起作用,您需要先安装它。@user1897085然后您需要安装Beauty Soup…您希望我安装哪个版本,因为我使用的是windows-7和python 2。7@user1897085Beauty Soup 4,如标题“下载Beauty Soup”下的链接所述。@user1897085不在计算机上,但是,要借鉴poke的建议,请查看Windows上的安装说明。