Попытка Scrap Следующая страница с Scrapy, Python 3.5, используя urlib библиотека ПитонаИспользование URLLIB с Scrapy для PAGINATION
import datetime
import urllib.request
import urllib.error
import urllib.parse
import socket
import scrapy
from scrapy.loader.processors import MapCompose, Join
from scrapy.loader import ItemLoader
from properties.items import PropertiesItem
class BasicSpider(scrapy.Spider):
name = "manual"
allowed_domains = ["web"]
# Start on the first index page
start_urls = (
'http://scrapybook.s3.amazonaws.com/properties/index_00000.html',
)
def parse(self, response):
# Get the next index URLs and yield Requests
next_selector = response.xpath('//*[contains(@class,"next")]//@href')
for url in next_selector.extract():
yield Request(urllib.parse.urljoin(response.url, url))
# Get item URLs and yield Requests
item_selector = response.xpath('//*[@itemprop="url"]/@href')
for url in item_selector.extract():
yield Request(urllib.parse.urljoin(response.url, url), callback=self.parse_item)
def parse(self, response):
l = ItemLoader(item=PropertiesItem(), response=response)
l.add_xpath('title', '//*[@itemprop="name"]/text()')
return l.load_item()
Всё отлично работает без ошибок, но Scrapy Fetching только первой страницы, но в соответствии с кодом он должен получать все последующие страницы
Вот выход
[{
"title": [
"bermondsey ec kennington drive acton seven rm",
.......
"mary conversion borders eastham with gas"
}]
// Only Page 0 Titles :(
ничего плохого запроса или URLLIB вызова Синтаксис?
PS: Xpath рабочий, Scrapy Shell 'URL'
Wow! Человек, ты Великий, Большое спасибо. –