我正在尝试废弃信息,我正在寻找的信息可以从搜索地址访问:[http://www.sec.gov/cgi-bin/srch-edgar?text=form-type%3Dd+and+state %3DMN&first=2008&last=2011][1]
我希望scrapy遵循书面链接(让我们尝试一个然后我将寻找生成与之相关的数字)一个链接的Xpath是:
/html/body/div/table/tbody/tr[29]/td[3]/a[2]
爬到这个链接后,我希望 scrappy 爬到下一页上可用的 xml 文件。链接的 Xpath 是通用的:
//*[@id="formDiv"]/div/table/tbody/tr[3]/td[3]/a
最后我想让scrapy从xml页面中抓取一些数据。
使用以下命令启动 Scrapy:scrapy crawl DFORM -o items.json -t json 我在 json 文件中得到的只是:“[”。
项目.py
from scrapy.item import Item, Field
class SecformD(Item):
company = Field()
filling_date = Field()
types_of_securities = Field()
offering_amount = Field()
sold_amount = Field()
remaining = Field()
investors_accredited = Field()
investors_non_accredited = Field()
* Formds_Crawler.py*
from scrapy.contrib.spiders import BaseSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import HtmlXPathSelector
from scrapy.selector import XmlXPathSelector
from formds.items import SecformD
class SecDform(CrawlSpider):
name = "DFORM"
allowed_domain = ["http://www.sec.gov"]
start_urls = [
"http://www.sec.gov/cgi-bin/srch-edgar?text=form-type%3Dd+and+state%3DMN&first=2008&last=2011"
]
rules = (
Rule(SgmlLinkExtractor(restrict_xpaths=('/html/body/div/table/tbody/tr[27]/td[3]/a[2]')), callback='parse_formd', follow= True),)
def parse_formd(self, response):
xxs = XMLPathSelector(response)
hsx = HtmlXPathSelector(response)
sites = xxs.select('//*[@id="formDiv"]/div/table/tbody/tr[3]/td[3]/a')
items = []
for site in sites:
item = SecFormD()
item['company'] = site.select('//*[@id="collapsible1"]/div[1]/div[2]/div[2]/span[2]/text()').extract()
item['filling_date'] = site.select('//*[@id="collapsible40"]/div[1]/div[2]/div[5]/span[2]/text()').extract()
item['types_of_securities'] = site.select('//*[@id="collapsible37"]/div[1]/div[2]/div[1]/span[2]/text()').extract()
item['offering_amount'] = site.select('//*[@id="collapsible39"]/div[1]/div[2]/div[1]/span[2]/text()').extract()
item['sold_amount'] = site.select('//*[@id="collapsible39"]/div[1]/div[2]/div[2]/span[2]/text()').extract()
item['remaining'] = site.select('//*[@id="collapsible39"]/div[1]/div[2]/div[3]/span[2]/text()').extract()
item['investors_accredited'] = site.select('//*[@id="collapsible40"]/div[1]/div[2]/div[2]/span[2]/text()').extract()
item['investors_non_accredited'] = site.select('//*[@id="collapsible40"]/div[1]/div[2]/div[1]/span[2]/text()').extract()
items.append(item)
return items
***Here is the log:***
USComputer:formds psykoboy$ scrapy crawl DFORM -o items.json -t json
2013-07-18 21:18:37-0500 [scrapy] INFO: Scrapy 0.16.4 started (bot: formds)
2013-07-18 21:18:38-0500 [scrapy] DEBUG: Enabled extensions: FeedExporter, LogStats, TelnetConsole, CloseSpider, WebService, CoreStats, SpiderState
2013-07-18 21:18:38-0500 [scrapy] DEBUG: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, RedirectMiddleware, CookiesMiddleware, HttpCompressionMiddleware, ChunkedTransferMiddleware, DownloaderStats
2013-07-18 21:18:38-0500 [scrapy] DEBUG: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware
2013-07-18 21:18:38-0500 [scrapy] DEBUG: Enabled item pipelines:
2013-07-18 21:18:38-0500 [DFORM] INFO: Spider opened
2013-07-18 21:18:38-0500 [DFORM] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2013-07-18 21:18:38-0500 [scrapy] DEBUG: Telnet console listening on 0.0.0.0:6023
2013-07-18 21:18:38-0500 [scrapy] DEBUG: Web service listening on 0.0.0.0:6080
2013-07-18 21:18:42-0500 [DFORM] DEBUG: Crawled (200) <GET http://www.sec.gov/cgi-bin/srch-edgar?text=form-type%3Dd%20and%20state%3DMN&start=81&count=80&first=2008&last=2011> (referer: None)
2013-07-18 21:18:43-0500 [DFORM] DEBUG: Crawled (200) <GET http://www.sec.gov/cgi-bin/srch-edgar?text=form-type%3Dd+and+state%3DMN&first=2008&last=2011> (referer: None)
2013-07-18 21:18:44-0500 [DFORM] DEBUG: Crawled (200) <GET http://www.sec.gov/cgi-bin/srch-edgar?text=form-type%3Dd%20and%20state%3DMN&start=161&count=80&first=2008&last=2011> (referer: None)
2013-07-18 21:18:45-0500 [DFORM] DEBUG: Crawled (200) <GET http://www.sec.gov/cgi-bin/srch-edgar?text=form-type%3Dd%20and%20state%3DMN&start=241&count=80&first=2008&last=2011> (referer: None)
2013-07-18 21:18:45-0500 [DFORM] DEBUG: Crawled (200) <GET http://www.sec.gov/cgi-bin/srch-edgar?text=form-type%3Dd%20and%20state%3DMN&start=321&count=80&first=2008&last=2011> (referer: None)
2013-07-18 21:18:46-0500 [DFORM] DEBUG: Crawled (200) <GET http://www.sec.gov/cgi-bin/srch-edgar?text=form-type%3Dd%20and%20state%3DMN&start=401&count=80&first=2008&last=2011> (referer: None)
2013-07-18 21:18:46-0500 [DFORM] DEBUG: Crawled (200) <GET http://www.sec.gov/cgi-bin/srch-edgar?text=form-type%3Dd%20and%20state%3DMN&start=481&count=80&first=2008&last=2011> (referer: None)
2013-07-18 21:18:47-0500 [DFORM] DEBUG: Crawled (200) <GET http://www.sec.gov/cgi-bin/srch-edgar?text=form-type%3Dd%20and%20state%3DMN&start=561&count=80&first=2008&last=2011> (referer: None)
2013-07-18 21:18:47-0500 [DFORM] DEBUG: Crawled (200) <GET http://www.sec.gov/cgi-bin/srch-edgar?text=form-type%3Dd%20and%20state%3DMN&start=641&count=80&first=2008&last=2011> (referer: None)
2013-07-18 21:18:48-0500 [DFORM] DEBUG: Crawled (200) <GET http://www.sec.gov/cgi-bin/srch-edgar?text=form-type%3Dd%20and%20state%3DMN&start=721&count=80&first=2008&last=2011> (referer: None)
2013-07-18 21:18:48-0500 [DFORM] DEBUG: Crawled (200) <GET http://www.sec.gov/cgi-bin/srch-edgar?text=form-type%3Dd%20and%20state%3DMN&start=721&count=80&first=2008&last=2011> (referer: None)
2013-07-18 21:18:48-0500 [DFORM] INFO: Closing spider (finished)
2013-07-18 21:18:48-0500 [DFORM] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 3419,
'downloader/request_count': 11,
'downloader/request_method_count/GET': 11,
'downloader/response_bytes': 68182,
'downloader/response_count': 11,
'downloader/response_status_count/200': 11,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2013, 7, 19, 2, 18, 48, 189346),
'log_count/DEBUG': 17,
'log_count/INFO': 4,
'response_received_count': 11,
'scheduler/dequeued': 11,
'scheduler/dequeued/memory': 11,
'scheduler/enqueued': 11,
'scheduler/enqueued/memory': 11,
'start_time': datetime.datetime(2013, 7, 19, 2, 18, 38, 701571)}
2013-07-18 21:18:48-0500 [DFORM] INFO: Spider closed (finished)