0

I'm trying to get value of javascript which is you can see below.

<script type="text/javascript" src="//media.flixfacts.com/js/loader.js" data-flix-distributor="7148" data-flix-language="tr" data-flix-brand="lg" data-flix-ean="8806087586213" data-flix-sku="1162559" data-flix-inpage="flix-inpage"></script>

I Tried this but its not worked.

ean = response.xpath('/html/head/script[25]/@data-flix-ean').extract_first()
5
  • Where's the page you're trying to scrape? We have no way to know what's wrong with your XPath if we can't see the page source. Commented Dec 17, 2016 at 12:43
  • I am just trying to get an attribute from this tag. I'm already getting already this tag. <script type="text/javascript" src="//media.flixfacts.com/js/loader.js" data-flix-distributor="7148" data-flix-language="tr" data-flix-brand="lg" data-flix-ean="8806087586213" data-flix-sku="1162559" data-flix-inpage="flix-inpage"></script> But I need the get data-flix-ean attribute Commented Dec 17, 2016 at 12:51
  • ...what is the url of the page you are trying to scrape. Like how the url of this page is stackoverflow.com/questions/41198101/… Commented Dec 17, 2016 at 14:54
  • @YPCrumble mediamarkt.com.tr/tr/product/… this is url Commented Dec 17, 2016 at 15:57
  • any help or suggestion ? Commented Dec 19, 2016 at 15:03

1 Answer 1

1

In the source code for that page you can find the following piece of code:

<script>
var sFlix = document.createElement('script');
    sFlix.setAttribute('type', 'text/javascript');
    sFlix.setAttribute('src', '//media.flixfacts.com/js/loader.js');
    sFlix.setAttribute('data-flix-distributor', '7148');
    sFlix.setAttribute('data-flix-language', 'tr');
    sFlix.setAttribute('data-flix-brand', Storm.DataLayer.data.user.productBrand.toLowerCase());
    sFlix.setAttribute('data-flix-ean', Storm.DataLayer.data.user.ean);
    sFlix.setAttribute('data-flix-sku', Storm.DataLayer.data.user.productId);
    sFlix.setAttribute('data-flix-inpage', 'flix-inpage');
    document.getElementsByTagName('head')[0].appendChild(sFlix);
    setTimeout(function(){ $(document).trigger('fee.fgrid_refresh'); }, 2000);
    setTimeout(function(){ $(document).trigger('fee.fgrid_refresh'); }, 4000);
    setTimeout(function(){ $(document).trigger('fee.fgrid_refresh'); }, 6000);
    setTimeout(function(){ $(document).trigger('fee.fgrid_refresh'); }, 20000);
    $('#flix-inpage').load(function() {
    $(document).trigger('fee.fgrid_refresh');
    }); 
    setTimeout(function(){ $(document).trigger('fee.fgrid_refresh'); }, 40000);
</script>

which means the script tag you are looking for is not actually in the received response, it's created dynamically. In order to extract the information you need, you should query the source of the data-flix-ean attribute, the Storm.DataLayer object:

response.xpath('/html/head/script/text()').re(r"Storm.DataLayer.put\('ean','(.*)'\);")

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.