I have written the following spider for scraping the webmd site for patient reviews
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
class MySpider(BaseSpider):
name = "webmd"
allowed_domains = ["webmd.com"]
start_urls = ["http://www.webmd.com/drugs/drugreview-92884-Boniva"]
def parse(self, response):
hxs = HtmlXPathSelector(response)
titles = hxs.select("//p")
title = titles.select("//p[contains(@class, 'comment')and contains(@style, 'display:none')]/text()").extract()
print(title)
Executing this code gives me desired output but with a lot of duplication i.e. the same comments are repeated for at least 10 times. Help me to solve this issue.