0

I need to get the data of productSkus[ using python but I don't know how to access it. the javascript comes from http://www.ulta.com/lid-lingerie-eye-tint?productId=xlsImpprod15361061 . This is how it looks like.

<script type="text/javascript">
  var currentSkuId = '2502111';
  var currentProductId = 'xlsImpprod15361061';

  var productSkus = new Object();

              productSkus[2502111] = 
                {"displayName":"Fame &amp; Fortune","id":"2502111","imgUrl":"http://images.ulta.com/is/image/Ulta/2502111?$detail$","largeImgUrl":"http://images.ulta.com/is/image/Ulta/2502111?$lg$","swatchImgUrl":"http://images.ulta.com/is/image/Ulta/2502111sw?$50px$","swatchHoverImgUrl":"http://images.ulta.com/is/image/Ulta/2502111sm?$md$","skuSize":"0.13","skuSizeUOM":"oz"};........

Can anyone help me with this?

3
  • 1
    Python runs on the server, Javascript runs on the client. You need to use AJAX to send the JS variable to the server. Commented Jul 4, 2017 at 7:19
  • Your question does not even make clear where the Javascript code snippet comes from and what you want to do with it. Is this your Python application or a page from a third party source you are trying to parse. Commented Jul 4, 2017 at 7:27
  • just edited my question. Commented Jul 4, 2017 at 7:34

2 Answers 2

1

If you want to use productSkus on the server side, then you need to use AJAX to send the JS variable to the server.

As Django template is compiled server side. It is then sent to the client where their browser executes the JavaScript. Nothing that is changed by the JavaScript executing on the client browser can have an affect on the template. It's too late at that point.

However the JavaScript could do something like make another request from the server for more information. Or you could just pre-compute the value on the server before you send it to the client.

You can of course use Django templates to set JavaScript variables.

<script>
    var myVar = '{{ py_var }}';
</script> 
Sign up to request clarification or add additional context in comments.

Comments

0

use html form to submit the data to server, or across api

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.