-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrapy1.py
More file actions
29 lines (23 loc) · 840 Bytes
/
Copy pathscrapy1.py
File metadata and controls
29 lines (23 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: utf-8 -*-
import sys, re
import scrapy
from scrapy.spiders import CrawlSpider, Rule, Request
from scrapy.linkextractors import LinkExtractor
from scrapy import FormRequest
reload(sys)
sys.setdefaultencoding('utf-8')
class HaoduofuliItem(scrapy.Item):
title = scrapy.Field()
class myspider(CrawlSpider):
name = 'soga'
allowed_domains = ['arthl.com']
start_urls = ['http://www.arthl.com']
rules = (
Rule(LinkExtractor(allow=('pn=(\d+)', )), follow=True),
Rule(LinkExtractor(allow=('show\-\d+\-\d+\.html', )),callback='parse_item', follow=True),
)
def parse_item(self, response):
url=response.url
title = response.xpath("//div[@class='showArea box']/h1/text()").extract()[0]
file_obj = open("log.txt", "a")
print >> file_obj,'%s %s' % (url, title)