python 使用scrappy阅读csv

csga3l58  于 2022-11-21  发布在  Python
关注(0)|答案(1)|浏览(127)

试图读取csv文件,但我得到错误,TypeError: Request url must be str, got list如何解决,请如何阅读列表任何建议推荐我

import scrapy
from scrapy.http import Request
import pandas as pd
from scrapy_selenium import SeleniumRequest
from io import open


class SampleSpider(scrapy.Spider):
    name = 'sample'
    with open("category.csv") as file:
            start_urls=[line.strip() for line in file]               
            
    def start_requests(self):
            request=Request(url=self.start_urls,callback=self.parse)
            yield request
       
            
    def parse(self, response):
            pass
abithluo

abithluo1#

您需要迭代列表并将每个url作为请求传递。

def start_requests(self):
        for url in self.start_urls:
            yield Request(url,callback=self.parse)

相关问题