So I have several problems that I am trying to tackle.
First I am trying to parse this javascript I got from html.
$(document).ready(function() { $('#commodity-show-thumbnails').bxSlider({ mode: 'vertical', auto: false, controls: true, pager: false, minSlides: 4, maxSlides: 4, moveSlides: 1, slideWidth: 250 }); itemSelector('commodity-show-form', 'commodity-show-addcart-submit', [['color', 'Choose color'], ['size', 'Choose size']], { "39805": { "params": ["Smokey Blue/Mica Blue", "36"]}, "39806": { "params": ["Smokey Blue/Mica Blue", "36,5"]}, "39807": { "params": ["Smokey Blue/Mica Blue", "37,5"]}, "39808": { "params": ["Smokey Blue/Mica Blue", "38"]}, "39809": { "params": ["Smokey Blue/Mica Blue", "38,5"]}, "39810": { "params": ["Smokey Blue/Mica Blue", "39"]}, "39811": { "params": ["Smokey Blue/Mica Blue", "40"]}, "39812": { "params": ["Smokey Blue/Mica Blue", "40,5"]}, "39814": { "params": ["Smokey Blue/Mica Blue", "42"]} }, [39805,39806,39807,39808,39809,39810,39811,39812,39814], 'main-cart', 'commodity-show-image'); });
res = re.findall(r'{ "params": (.+?)}', text) # text is where javascript text is stored
final = [eval(i) for i in res]
print(final)
I got following output
[['Smokey Blue/Mica Blue', '36'], ['Smokey Blue/Mica Blue', '36,5'], ['Smokey Blue/Mica Blue', '37,5'], ['Smokey Blue/Mica Blue', '38'], ['Smokey Blue/Mica Blue', '38,5'], ['Smokey Blue/Mica Blue', '39'], ['Smokey Blue/Mica Blue', '40'], ['Smokey Blue/Mica Blue', '40,5'], ['Smokey Blue/Mica Blue', '42']]
But now I don't know how to go from here on.I want to find the value this value 39805 from
{ "39805": { "params": ["Smokey Blue/Mica Blue", "36"]}. How would I parse it so that says if I am looking for value associated with 36, it would give me 39805?
I am sorry but I am really bad with parsing and I am pretty new to this.
{39805':'36', '39807':'37',...}is that correct?selenium,dryscrape,ghost.py. They will render the JS so you can access the HTML it generates.