【发布时间】:2014-06-19 07:47:37
【问题描述】:
我尝试复制和粘贴站点的元素(xpath),但没有返回任何结果。
scrapy 可以抓取 iframe 内的数据吗?如果是,如何做,如果不是,还应该做哪些其他事情?谢谢!
rules = (Rule (SgmlLinkExtractor(deny = path_deny_base, restrict_xpaths=('*'))
, callback="parse", follow= True),
)
def parse(self, response):
yield(Request(url, callback = self.parse_iframe))
def parse_iframe(self, response):
#your code to scrape the content from iframe
#def parse_items(self, response):
hxs = HtmlXPathSelector(response)
titles = hxs.select('//div[2]/h1')
#//div[2]/h1
linker = hxs.select('//div[2]/div[10]/a[1]')
#//div[2]/div[10]/a[1]
loc_Con = hxs.select('//div[2]/div[1]/div[2]/span/span/span[1]') #//div[2]/div[1]/div[2]/span/span/span[1]
loc_Reg = hxs.select('//div[2]/div[1]/div[2]/span/span/span[2]') #/div[2]/div[1]/div[2]/span/span/span[2]
loc_Loc = hxs.select('//div[2]/div[1]/div[2]/span/span/span[3]') #/div[2]/div[1]/div[2]/span/span/span[3]
items = []
for titles in titles:
item = CraigslistSampleItem()
#item ["job_id"] = id.select('text()').extract()[0].strip()
item ["title"] = map(unicode.strip, titles.select('text()').extract()) #ok
item ["link"] = linker.select('@href').extract() #ok
item ["info"] = (response.url)
temp1 = loc_Con.select('text()').extract()
temp2 = loc_Reg.select('text()').extract()
temp3 = loc_Loc.select('text()').extract()
temp1 = temp1[0] if temp1 else ""
temp2 = temp2[0] if temp2 else ""
temp3 = temp3[0] if temp3 else ""
item["code"] = "{0}-{1}-{2}".format(temp1, temp2, temp3)
items.append(item)
return(items)
【问题讨论】:
标签: python web-scraping scrapy