Jupyter Notebook中运行Python代码的问题:GoodReadsScraper

问题描述 投票:0回答:1

首先,我想让你知道我是一个外行。我只是在几周前才开始使用Python,所以我对此并不陌生,并且还不熟悉很多必要的术语。我将非常感谢您的帮助!

[我想尝试Omar Einea的Goodreads评论刮板(https://github.com/OmarEinea/GoodReadsScraper)。我按照他的指示,并使用pip安装了beautifulsoup4,langdetect,selenium和lxml。我将他的部分代码从reviews.py复制粘贴到Jupyter Notebook进行测试,然后运行以下单元格:

from Tools import SafeThread
from bs4 import BeautifulSoup
from langdetect import detect
from Browser import Browser
from Writer import Writer

但是,出现以下错误:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-5-4dc46ca353f6> in <module>
----> 1 from Tools import SafeThread
      2 from bs4 import BeautifulSoup
      3 from langdetect import detect
      4 from Browser import Browser
      5 from Writer import Writer

ImportError: cannot import name 'SafeThread' from 'Tools' (unknown location)

我以为也许我必须先安装工具,所以我跑了Python程式码:

pip install tools

在命令行中,但是我收到消息说它已经被安装:

C:\Users\Lore>pip install Tools
Requirement already satisfied: Tools in c:\users\xxx\appdata\local\programs\python\python38-32\lib\site-packages (0.1.9)
Requirement already satisfied: pytils in c:\users\xxx\appdata\local\programs\python\python38-32\lib\site-packages (from Tools) (0.3)
Requirement already satisfied: six in c:\users\xxx\appdata\local\programs\python\python38-32\lib\site-packages (from Tools) (1.13.0)
Requirement already satisfied: lxml in c:\users\xxx\appdata\local\programs\python\python38-32\lib\site-packages (from Tools) (4.4.2)

您对我如何能够解决此问题有任何想法吗?

我还有另一个问题。到目前为止,我只在/使用jupyter笔记本工作。有没有更好的方式/地方来编写和运行Python脚本/命令?

我尝试通过在“ IDLE”中打开它并单击“运行”来运行“ Reviews.py”中的整个代码,但这给了我这个:

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
======= RESTART: C:\Users\xxx\Desktop\GoodReadsScraper-master\Reviews.py ======
>>> 

预先感谢您的帮助和理解!

python web-scraping jupyter-notebook python-idle
1个回答
0
投票

Review.py中引用的“工具”为this script called 'Tools' in the repository you reference

pip install tools一起安装的东西与此无关。您可以看到它here

如果您将the repository中的所有代码下载下来,然后在将工作目录设置为该目录的情况下尝试运行该程序,那么您会更轻松。在笔记本中,您可以使用pwd打印您的工作目录。您可以使用%cd进行更改。

© www.soinside.com 2019 - 2024. All rights reserved.