我正在使用 ScrapeGraphAI 做一个简单的示例,可以在此链接中找到ScrapeGraphAI Github。
我已经在虚拟环境中安装了软件包,如链接所示:
pip install scrapegraphai
playwright install
但是当我运行代码时,我收到以下错误消息:
File "C:\...\Python\ScrapeGraphAI\scrapegraphai.py", line 2, in <module>
from scrapegraphai.graphs import SmartScraperGraph
ModuleNotFoundError: No module named 'scrapegraphai.graphs'; 'scrapegraphai' is not a package
如果一切都安装正确,可能会出现什么问题?
这是完整的代码。如果您想运行它,只需将“您的 API 密钥”替换为您的 API 密钥即可。
import json
from scrapegraphai.graphs import SmartScraperGraph
# Define the configuration for the scraping pipeline
graph_config = {
"llm": {
"api_key": "YOUR API KEY",
"model": "gpt-4o-mini",
},
"verbose": True,
"headless": False,
}
# Create the SmartScraperGraph instance
smart_scraper_graph = SmartScraperGraph(
prompt="Find some information about what does the company do, the name and a contact email.",
source="https://scrapegraphai.com/",
config=graph_config
)
# Run the pipeline
result = smart_scraper_graph.run()
print(json.dumps(result, indent=4))
不要让你的 python 文件与包同名。您的文件名为
scrapegraphai.py
,因此 from scrapegraphai ...
尝试从该文件而不是包中加载。只需重命名您的文件即可。