我不知道为什么,但是最近有一个错误:
File "C:\Users\name\PycharmProjects\splash\project\project\spiders\scrapy.py", line 5, in <module>
class ScrapySpider(scrapy.Spider):
AttributeError: 'module' object has no attribute 'Spider'
我的完整代码:
import scrapy
from scrapy_splash import SplashRequest
class Spider(scrapy.Spider):
name = "spide"
start_urls = [
many links
]
def start_requests(self):
for url in self.start_urls:
yield SplashRequest(url, self.parse,
endpoint='render.html',
args={'wait': 0.5},
)
def parse(self, response):
"my parsed info"
有什么问题,如何解决?
P.S。我通过this tutorial
设置了ScrapySplash答案 0 :(得分:1)
问题出在您的python文件的名称中:
dir: error: pasting ")" and "_" does not give a valid preprocessing token
INTERNAL(sym) \
--- NOTE--- EXPORT_FUNCTION_MACRO takes args 'sys' and 'n'
other_dir: note: in definition of macro ‘EXPORT_FUNCTION_MACRO’
void _example##sym##_##n(void) {} \
跑步时
using f(a, b) = f_internal(a);
Python试图将当前文件(您已在其中编写代码)导入为scrapy模块。要解决此问题,请将文件重命名为C:\Users\name\PycharmProjects\splash\project\project\spiders\scrapy.py
以外的名称。这意味着,当Python尝试进行import scrapy
时,假设您已正确安装scrapy(scrapy.py
),它将在import scrapy
文件夹中导入scrapy.py
文件。>