scrapy yield Request

复制代码
import scrapy
from myproject.items import MyItem
class MySpider(scrapy.Spider):
name = ’example.com’ allowed_domains = [’example.com’] start_urls = [
        ’http://www.example.com/1.html’,
        ’http://www.example.com/2.html’,
        ’http://www.example.com/3.html’,
]
def parse(self, response):   for h3 in response.xpath(’//h3’).extract():     yield MyItem(title=h3)
  
for url in response.xpath(’//a/@href’).extract():
    yield scrapy.Request(url, callback=self.parse)
复制代码

 

posted @   samu  阅读(1123)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示