0

インポートしようとすると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
>>>

編集

>>> 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

>

編集1

>>> 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
>>>

アップデート

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
>>>

ありがとう、

4

1 に答える 1

7

大文字にしてみるBeautifulSoup

from BeautifulSoup import BeautifulSoup

BS4 を使用している場合:

from bs4 import BeautifulSoup

@pokeがインテリジェントに提案したように、BeautifulSoupインストールしたことを確認することが重要です:) WindowsでのBSのインストールについて説明しているこれを試してください: Windows でPython 2.7を使用して美しいスープ4をインストールする方法

于 2012-12-26T22:18:41.457 に答える