I'm using Scrapy to crawl a web page which contains a specific article.
I'm trying to get the informations stored inside the div with the class "return". The big problem that the div return always empty when i use Scrapy Xpath or Css selectors.
The Div that i'm trying to extract:
<div class="return">
<p><strong>Conditionnement : </strong></p>
<p class="one-product-detail">2 colis :<br>
L178xl106xH80 72kg<br>L178xl112xH80 60kg<br>
<span itemprop="weight" alt="3fin" class="hidden" hidden="">132kg</span></p>
</div>
My Spider Code:
import scrapy
from alinea.items import AlineaItem
class AlineaSpider(scrapy.Spider):
name = "alinea"
start_urls = [
"http://www.alinea.fr/",
]
def parse(self, response):
# ref = input("Enter Item Reference ?\n")
# 25321050
# link = "http://www.alinea.fr/alinea_fredhopper/catalogSearch_result/products/search/" + str(ref)
link = "http://www.alinea.fr/alinea_fredhopper/catalogSearch_result/products/search/" + str(25321050)
print(link)
return scrapy.Request(link,
callback=self.parse_page2)
def parse_page2(self, response):
self.logger.info("Visited %s", response.url)
for sel in response.xpath('//li[contains(@itemprop,"title")]/text()'):
print("**************")
print("Description")
print(sel.extract())
print("**************")
# print("------------------------------------------------------------------")
#
# for sel in response.xpath('//*[@class="delivery"]'):
#
# print("**************")
# print("Details")
# print(sel.extract())
# print("**************")
print("------------------------------------------------------------------")
for sel in response.css('[class="return"]'):
print("**************")
print("Details")
print(sel.extract())
print("**************")
My Terminal Log:
2016-07-28 12:57:21 [alinea] INFO: Visited http://www.alinea.fr/orca-canape-angle-gauche-droit-convertible-gris.html
**************
Description
Orca - Canapé CONVERTIBLE d'angle gauche ou droit gris
**************
------------------------------------------------------------------
**************
Details
<div class="return">
</div>
**************
divis empty in the HTML source. It's also empty in my Chrome browser, until you select an option for the product. I tested with alinea.fr/orca-canape-angle-gauche-droit-convertible-gris.html. The data you're after is most probably loaded through JavaScript. Scrapy itself only downloads HTML, and does not intepret JavaScript. You'll need to either reproduce the XHR call or use a JavaScript rendering tool, like Selenium or Splash. - paul trmbrth