I just started crawling. I'm trying to crawl question and answers from website http://www.indiabix.com/verbal-ability/spotting-errors/ by downloading content using Scrapy framework and Python 2.7. I noticed that if you view its source, you'll notice that answer for every question should be in the b tag but its not:
<div class="div-spacer">
<p><span class="ib-green"><b>Answer:</b></span> Option <b class="jq-hdnakqb"></b></p>
<p><span class="ib-green"><b>Explanation:</b></span></p>
<p> No answer description available for this question. <b><a href="discussion-399">Let us discuss</a></b>. </p>
If we inspect element on the webpage we can see the correct answer as text between the tags : Answer: Option A or B etc. for each question but the HTML source code doesn't.
To get the text within the b tag I've tried around 15 queries using xpath. Ive written the most probable 4-5 queries as comments in the code below.
import scrapy
import urllib
import json
from errors1.items import Errors1Item
class Errors1Spider(scrapy.Spider) :
name = "errors1"
start_urls = ["http://www.indiabix.com/verbal-ability/spotting-errors/"]
def parse(self, response) :
i = 0
y = 0
j = json.loads(json.dumps(response.xpath('//td[contains(@id, "tdOption")]/text()').extract()))
x = json.loads(json.dumps(response.xpath('//div[@class="div-spacer"]/p[3]/text()').extract()))
#to get correct answer
#response.xpath('//div[@class = "div-spacer"]/p/b/text()').extract()
#response.xpath('//div[@class = "div-spacer"]/p[1]/b/text()').extract()
#response.xpath('//div[@class = "div-spacer"]/p//text()').extract()
#response.xpath('//b[@class = "jq-hdnakqb"]/text()').extract()
#response.xpath('string(//div[@class = "div-spacer"]/p/b/text())').extract()
while i<len(j) and y<len(x) :
item = Errors1Item()
item['optionA'] = j[i]
i+=1
item['optionB'] = j[i]
i+=1
item['optionC'] = j[i]
i+=1
item['optionD'] = j[i]
i+=1
item['explanation'] = x[y]
y+=1
yield item
Can someone please help me get the answer content from that webpage. Thanks