0

我已经在我的 windows7 PC 中安装了 python 2.7。现在我浏览了Beautiful Soup。现在我找到了两个安装 BeautifulSoup4 的命令。easy_install beautifulsoup4pip install beautifulsoup4。但我的困惑是我必须在哪个目录中运行这些命令。我的python文件夹是C:\Python27。你能帮我在哪里运行该命令吗?

错误

    Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Arup Rakshit>cd..

C:\Users>cd..

C:\>cd C:\Python27

C:\Python27>python.exe virtualenv.py selenv
New python executable in selenv\Scripts\python.exe
Installing setuptools....................................done.
Installing pip.........................done.

C:\Python27>cd selenv\Scripts\

C:\Python27\selenv\Scripts>pip.exe install selenium
Downloading/unpacking selenium
  Downloading selenium-2.28.0.tar.gz (2.1MB): 2.1MB downloaded
  Running setup.py egg_info for package selenium
    C:\Python27\Lib\distutils\dist.py:267: UserWarning: Unknown distribution opt
ion: 'src_root'
      warnings.warn(msg)

    warning: no files found matching 'docs\api\py\index.rst'
Installing collected packages: selenium
  Running setup.py install for selenium
    C:\Python27\Lib\distutils\dist.py:267: UserWarning: Unknown distribution opt
ion: 'src_root'
      warnings.warn(msg)

    warning: no files found matching 'docs\api\py\index.rst'
Successfully installed selenium
Cleaning up...

C:\Python27\selenv\Scripts>python.exe my_selenium_script.py
python.exe: can't open file 'my_selenium_script.py': [Errno 2] No such file or d
irectory

C:\Python27\selenv\Scripts>python.exe my_selenium_script.py
Hello

C:\Python27\selenv\Scripts>cd..

C:\Python27\selenv>pip install beautifulsoup4
'pip' is not recognized as an internal or external command,
operable program or batch file.

C:\Python27\selenv>

谢谢

4

1 回答 1

0

Beautiful Soup 4 是通过 PyPi 发布的,所以如果你不能用系统打包器安装它,你可以用 easy_install 或 pip 安装它。包名称是 beautifulsoup4,相同的包适用于 Python 2 和 Python 3。

$ easy_install beautifulsoup4

$ pip install beautifulsoup4

如果您没有安装 easy_install 或 pip,您可以下载Beautiful Soup 4源代码压缩包并使用 setup.py 安装它。[转到该文件夹​​并运行命令 setup.py install(假设 *.py 在路径扩展名中已知,否则运行 c:\python25\python setup.py install)。]

C:\Python27\beautifulsoup4-4.1.0>cd C:\Python27\beautifulsoup4-4.1.0
C:\Python27\beautifulsoup4-4.1.0>setup.py install 'here I am done!

测试 :

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Arup Rakshit>cd..

C:\Users>cd..

C:\>cd C:\Python27

C:\Python27>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("http://www.google.com/"))
>>> tables = source.findAll('td')
>>> import csv
>>> writer = csv.writer(open('filename.csv','w'))
>>> writer.writerow(rows)
于 2013-01-03T21:08:55.577 回答