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 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
,然后重试。