因此,我正在尝试使用python进行网络抓取。我从这里开始使用this教程,并且在命令行上使用python都可以正常工作
如此处所示
web scraping using google search
但是,当我尝试在sublime text 3中运行相同的代码时,会出现此错误
Traceback (most recent call last):
File "H:\Gits\googlesearch.py", line 2, in <module>
import googlesearch
File "H:\Gits\googlesearch.py", line 3, in <module>
for url in googlesearch.search('"Breaking Code" WordPress blog', stop=20):
AttributeError: module 'googlesearch' has no attribute 'search'
[Finished in 0.1s with exit code 1]
[cmd: ['C:/ProgramData/Anaconda3/pkgs/python-3.6.6-hea74fb7_0/python.exe',
'-u', 'H:\\Gits\\googlesearch.py']]
[dir: H:\Gits]
[path:
C:\ProgramData\Anaconda3;C:\ProgramData\Anaconda3\Library\mingw-
w64\bin;
C:\ProgramData\Anaconda3\Library\usr\bin;
C:\ProgramData\Anaconda3\Library\bin;
C:\ProgramData\Anaconda3\Scripts;
C:\ProgramData\Oracle\Java\javapath;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\libnvvp;
C:\Program Files (x86)\Razer Chroma SDK\bin;
C:\Program Files\Razer Chroma SDK\bin;C:\WINDOWS\system32;
C:\WINDOWS;C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
C:\Program
Files\Git\cmd;C:\Users\delengowski\AppData\Local\Microsoft\WindowsApps;
C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\Program Files\HDF_Group\HDF5\1.10.1\bin\;
C:\Program Files\PuTTY\;
C:\Program Files\MATLAB\R2018a\runtime\win64;
C:\Program Files\MATLAB\R2018a\bin;
C:\MinGW\bin;
C:\Program Files (x86)\Wolfram Research\WolframScript\;
C:\Program Files\doxygen\bin;
C:\WINDOWS\System32\OpenSSH\;
C:\Users\delengowski\AppData\Local\Microsoft\WindowsApps;
C:\Program Files\Microsoft VS Code\bin;
C:\ProgramData\Anaconda3\pkgs\python-3.6.4-h6538335_1;
C:\texlive\2017\bin\win32;
C:\MinGW\bin;
c:\programdata\anaconda3\lib\site-packages;]
我正在通过Anaconda使用python 3.6,并且正在使用此构建设置来构建python
{
"cmd": ["C:\\ProgramData\\Anaconda3\\python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env" :
{
"PYTHONPATH": "C:\\ProgramData\\Anaconda3\\Lib"
}
}
在崇高的氛围中,我同时安装了Anaconda和Conda软件包
我可以使用此构建设置构建简单的python脚本,例如简单
print("Hello World")
答案 0 :(得分:0)
您的脚本名为googlesearch.py
,因此,当您执行import googlesearch
时,您将获得自己的脚本,而不是真正的googlesearch软件包模块。
用googlesearch.py
以外的名称命名脚本。