【发布时间】:2016-07-25 04:34:03
【问题描述】:
伙计们,我想从this link 一切都还好,我的刮成功了
然后我在想,如果我想抓取所有页面怎么样(第一页直到无穷大取决于数据库文章)
我是使用 python 和 scrapy 的新手,在此之前我使用 java 和 c#...他们两个与 python 非常不同,但对我来说还可以
这是我的来源
import datetime
import urlparse
import socket
import scrapy
from scrapy.loader.processors import MapCompose, Join
from scrapy.loader import ItemLoader
from scrapy.http import Request
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from thehack.items import NowItem
class MySpider(BaseSpider):
name = "nowhere"
allowed_domains = ["n0where.net"]
start_urls = ["https://n0where.net/"]
def parse(self, response):
# Get the next index URLs and yield Requests
next_selector = response.xpath('/html/body/div[4]/div[3]/div/div/div/div/div[1]/div/div[6]/div/a[8]')
for url in next_selector.extract():
yield Request(urlparse.urljoin(response.url, url))
def parse(self, response):
for article in response.css('.loop-panel'):
item = NowItem()
item['title'] = article.css('.article-title::text').extract_first()
item['link'] = article.css('.overlay-link::attr(href)').extract_first()
item['body'] ='' .join(article.css('.excerpt p::text').extract()).strip()
yield item
有人知道如何解决我的问题,我的来源没问题,但它只抓取第 1 页,如果我想自动抓取下一页如何?
先谢谢队友 :)
【问题讨论】:
标签: python xpath web-scraping css-selectors scrapy