You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Scrapy传入计算生成的列表作为起始URL报错,硬编码URL正常如何解决?

问题修复方案

核心错误原因

Scrapy 框架规定爬虫类的起始URL列表属性必须命名为 start_urls(末尾带s),你当前代码中将该属性名写为 start_url(缺少末尾的s),和报错提示的内容完全匹配。你注释掉的硬编码测试代码用的是正确的属性名 start_urls,所以运行正常。

修复方法

直接修改对应行的属性名即可:
将原代码中的:

start_url = ["https://www.screener.in/company/" + e + "/consolidated/" for e in comp1]

替换为:

start_urls = ["https://www.screener.in/company/" + e + "/consolidated/" for e in comp1]

可选优化点

  • 读取CSV后可先做空值过滤,避免url列存在空值拼接出无效请求地址
  • 拼接URL前可以对读取到的e做去首尾空格处理,避免CSV导出时带多余空格导致请求404,写法参考:
    start_urls = ["https://www.screener.in/company/" + e.strip() + "/consolidated/" for e in comp1 if pd.notna(e)]
    

内容的提问来源于stack exchange,提问作者ETWAS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 17:18:03