Skip to content

Instantly share code, notes, and snippets.

@diablowu
Created September 22, 2015 14:29
Show Gist options
  • Select an option

  • Save diablowu/a1c8eea4438175eeaf45 to your computer and use it in GitHub Desktop.

Select an option

Save diablowu/a1c8eea4438175eeaf45 to your computer and use it in GitHub Desktop.
HaojuSpider
# -*- coding: utf-8 -*-
import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
from scrapy import Request
from telnum.items import TelnumItem
class HaojuSpider(CrawlSpider):
name = "haoju"
allowed_domains = ["shouji.dongganchaoren.com"]
start_urls = (
'http://shouji.dongganchaoren.com/',
)
rules = [
Rule(LinkExtractor(allow=('/haoduan/[0-9]{3,3}/[0-9]{4,4}', )), callback='parse_hd')
]
def parse_hd(self, response):
s = response.xpath('//table/tr/td[1]/a')
items = []
for dd in s:
it = TelnumItem()
it['code'] = s.xpath('./text()').extract()
it['url'] = s.xpath('./@href')[0].extract()
items.append(it)
return items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment