Python 中的 Scrapy 安装问题

问题描述 投票:0回答:1
from scrapy import Selector

# Import requests
import requests

url = 'https://en.wikipedia.org/wiki/Pakistan'

# Fetch the HTML content of the webpage
response = requests.get(url)

# Create the Selector object sel from html
sel = Selector(text=response.text)

# Print out the number of elements in the HTML document
print("You have found:", len(sel.xpath('//*')))

我是网络抓取的初学者,尝试了以下命令来测试。但这个错误来了。

在此输入图片描述

我尝试重新安装 scrappy 模块并检查 Python 版本。但仍然出现错误。

python html css web-scraping scrapy
1个回答
0
投票

该问题是因为您尝试在Python 3.11中使用python312.DLL而引起的。具体来说,这是Scrapy的问题。

通常你可以通过使用pip重新安装Scrapy来解决这个问题。但考虑到它没什么用,这是我的建议。

首先需要检查Scrapy的版本。确保您实际上使用的是与 Python 3.11 兼容的 Scrapy 版本。

当地环境复杂。如果您仍然遇到此问题,请尝试通过

python -m venv my_env
conda create --name my_env python=3.11

创建虚拟环境

然后通过

.\myenv\Scripts\activate
conda activate my_env

激活它

pip install scrapy
,然后重试。

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