我试图取消所有的链接,这也是在网站上分页。下面给出的是我的代码,但代码不工作。它只是从第一页删除url链接。我该如何取消所有链接?谢谢
# -*- coding: utf-8 -*-
import scrapy
class DummySpider(scrapy.Spider):
name = 'dummyspider'
allowed_domains = ['alibaba.com']
start_urls = ['https://www.alibaba.com/countrysearch/CN/China/products/A.html'
]
def parse(self, response):
link = response.xpath('//*[@class="column one3"]/a/@href').extract()
for item in zip(link):
scraped_info = {
'link':item[0],
}
yield scraped_info
next_page_url = response.xpath('//*[@class="page_btn"]/@href').extract_first()
if next_page_url:
next_page_url = response.urljoin(next_page_url)
yield scrapy.Request(url = next_page_url, callback = self.parse)
起始url是https://www.alibaba.com/countrysearch/CN/China/products/A.html
您可以通过正确设置起始URL来解决这个问题。你知道吗
string
模块具有字母常量:您可以使用以编程方式创建URL:
相关问题 更多 >
编程相关推荐