我正在使用scrapy抓取蜘蛛並試圖解析輸出頁面來選擇一些輸入標籤參數(類型,id,名稱),每個數據類型被選中到一個項目因此,這將是存儲在數據庫以後類似的東西:提取正確的值形式輸入標籤..提供的圖像:)
Database Table_1
╔════════════════╗
║ text ║
╠════════════════╣
║ id │ name ║
╟──────┼─────────╢
║ │ ║
╟──────┼─────────╢
║ │ ║
╚══════╧═════════╝
同樣會在密碼和文件,但
我面對的是,XPath的提取整個標籤的問題!
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import HtmlXPathSelector
from scrapy.item import Item, Field
from isa.items import IsaItem
class MySpider(CrawlSpider):
name = 'example.com'
allowed_domains = ['testaspnet.vulnweb.com']
start_urls = ['http://testaspnet.vulnweb.com']
rules = (
Rule(SgmlLinkExtractor(allow=('/*')),callback='parse_item'),)
def parse_item(self, response):
self.log('%s' % response.url)
hxs = HtmlXPathSelector(response)
item=IsaItem()
text_input=hxs.select("//input[(@id or @name) and (@type = 'text')]").extract()
pass_input=hxs.select("//input[(@id or @name) and (@type = 'password')]").extract()
file_input=hxs.select("//input[(@id or @name) and (@type = 'file')]").extract()
print text_input , pass_input ,file_input
return item
輸出
[email protected]:~/isa/isa$ scrapy crawl example.com -L INFO -o file_nfffame.csv -t csv
2012-07-02 12:42:02+0200 [scrapy] INFO: Scrapy 0.14.4 started (bot: isa)
2012-07-02 12:42:02+0200 [example.com] INFO: Spider opened
2012-07-02 12:42:02+0200 [example.com] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
[] [] []
[] [] []
[] [] []
[u'<input name="tbUsername" type="text" id="tbUsername" class="Login">'] [u'<input name="tbPassword" type="password" id="tbPassword" class="Login">'] []
[] [] []
[u'<input name="tbUsername" type="text" id="tbUsername" class="Login">'] [u'<input name="tbPassword" type="password" id="tbPassword" class="Login">'] []
[] [] []
2012-07-02 12:42:08+0200 [example.com] INFO: Closing spider (finished)
正確的輸出應該是什麼樣子? –
@stav for type text >> [id,name],用於輸入密碼[id,name],正好[「tbUsername」,「tbUsername」],[「tbPassword」,「tbPassword」],我知道有一個重複值,但是這是因爲這個表單ID =名稱 –