我正在尝试将+1
添加到网址并抓取多个页面,但是我在+ x
部分上总是遇到错误
import scrapy
#formatted here
class HeadphonesSpider(scrapy.Spider):
name = "headphones"
def start_requests(self):
for x in range(5):
x = str (x)
url = 'https://www. domain .com/page=' + x
yield scrapy.Request(url=url, callback=self.parse)
def parse(self, response):
img_urls = response.css('div.job-title a::attr(href)').extract()
with open('urls.txt', 'w') as f:
for u in img_urls:
f.write(u + "\n")