Posted March 04, 2016
![mrkgnao](https://images.gog.com/c122e53a8f42189d8f91ab9adcfa4a6f31dbf48d3ad07a891b6b2ed0e1ea8a1f_forum_avatar.jpg)
mrkgnao
https://www.amazon.com/dp/B00HCZVCTO
Registered: Apr 2009
From United States
![rtcvb32](https://images.gog.com/77665aa6affc77960e6b537ee348222af4d3fecc684f14d10088eae491b41e33_forum_avatar.jpg)
rtcvb32
echo e.lolfiu_fefiipieue|tr valueof_pi [0-9]
Registered: Aug 2013
From United States
Posted March 04, 2016
A while back i requested information on the API so i could build a little trading page for people to use, mostly that checked and ensured games on a gift coupon existed and weren't expired without giving the codes away (unless both agreed to the trade(s)), never got any feedback. Something like a week later they changed to using move Java and JQuery making it more difficult for me.
Oh well.
Oh well.
![eiii](https://images.gog.com/8233fa4d06abcaf2c477cc3de7d65efd5dda42dc05cfecc5c282d620f57284b3_forum_avatar.jpg)
eiii
#%&@#%
Registered: Dec 2013
From San Marino
Posted March 17, 2016
Is there any way to request the data of a promo page, like the list of the games and the prices?
![skeletonbow](https://images.gog.com/3a6ffc77c3410e96ecd2e5775b3fed422e1acdd05bbf19cd366e44ae40b03b34_forum_avatar.jpg)
skeletonbow
Galaxy 3 when?
Registered: Dec 2009
From Canada
Posted March 17, 2016
![avatar](http://images.gog.com/8233fa4d06abcaf2c477cc3de7d65efd5dda42dc05cfecc5c282d620f57284b3_avm.jpg)
![adaliabooks](https://images.gog.com/c90963e355fe1295789b379c4a4da768cbe394dc8b4c54439a31b01bfa2febc8_forum_avatar.jpg)
adaliabooks
"Vell, Zaphod's just zis guy, you know?"
Registered: Jun 2013
From United Kingdom
Posted March 17, 2016
![avatar](http://images.gog.com/8233fa4d06abcaf2c477cc3de7d65efd5dda42dc05cfecc5c282d620f57284b3_avm.jpg)
On my phone now so I can't use the console to figure out what you'd need to do.
![adaliabooks](https://images.gog.com/c90963e355fe1295789b379c4a4da768cbe394dc8b4c54439a31b01bfa2febc8_forum_avatar.jpg)
adaliabooks
"Vell, Zaphod's just zis guy, you know?"
Registered: Jun 2013
From United Kingdom
Posted March 17, 2016
![avatar](http://images.gog.com/8233fa4d06abcaf2c477cc3de7d65efd5dda42dc05cfecc5c282d620f57284b3_avm.jpg)
angular.reloadWithDebugInfo();
Which will refresh the page and enable debugging to make the .scope() function work.
You need to be on the promo page itself (either in the console, injecting a userscript or using an AJAX call), then run this function:
var scope = angular.element(document.querySelectorAll('.promo-columns-wrapper')).scope();
This will return an object with quite a few properties, the ones you'd probably be interested in are;
scope.data.products which contains a list of all the products (owned and unowned) which you can then do what you like with.
scope.notOwnedProducts which is an array of just the products you don't own.
scope.ownedProducts which is just the games you do own.
Hope that helps :)
![eiii](https://images.gog.com/8233fa4d06abcaf2c477cc3de7d65efd5dda42dc05cfecc5c282d620f57284b3_forum_avatar.jpg)
eiii
#%&@#%
Registered: Dec 2013
From San Marino
![adaliabooks](https://images.gog.com/c90963e355fe1295789b379c4a4da768cbe394dc8b4c54439a31b01bfa2febc8_forum_avatar.jpg)
adaliabooks
"Vell, Zaphod's just zis guy, you know?"
Registered: Jun 2013
From United Kingdom
Posted March 17, 2016
![avatar](http://images.gog.com/8233fa4d06abcaf2c477cc3de7d65efd5dda42dc05cfecc5c282d620f57284b3_avm.jpg)
What exactly were you looking to do? Scrape the promos to create a list of titles and prices?
![eiii](https://images.gog.com/8233fa4d06abcaf2c477cc3de7d65efd5dda42dc05cfecc5c282d620f57284b3_forum_avatar.jpg)
eiii
#%&@#%
Registered: Dec 2013
From San Marino
Posted March 17, 2016
![avatar](http://images.gog.com/fc8ebd082c233822f091875ad36c1102a4a7d58be19b73e72c997de681aa40f1_avm.jpg)
![adaliabooks](https://images.gog.com/c90963e355fe1295789b379c4a4da768cbe394dc8b4c54439a31b01bfa2febc8_forum_avatar.jpg)
adaliabooks
"Vell, Zaphod's just zis guy, you know?"
Registered: Jun 2013
From United Kingdom
Posted March 17, 2016
![avatar](http://images.gog.com/8233fa4d06abcaf2c477cc3de7d65efd5dda42dc05cfecc5c282d620f57284b3_avm.jpg)
A userscript would probably be easiest to make (you could just run it and then paste the output where you wanted it) but I could put a page on my server with the rest of my script stuff that would do it for you and return a JSON output (or whatever format you wanted really). All you'd need to do is go to the url and maybe add the promo page url as a variable..
![eiii](https://images.gog.com/8233fa4d06abcaf2c477cc3de7d65efd5dda42dc05cfecc5c282d620f57284b3_forum_avatar.jpg)
eiii
#%&@#%
Registered: Dec 2013
From San Marino
Posted March 17, 2016
![avatar](http://images.gog.com/fc8ebd082c233822f091875ad36c1102a4a7d58be19b73e72c997de681aa40f1_avm.jpg)
A userscript would probably be easiest to make (you could just run it and then paste the output where you wanted it) but I could put a page on my server with the rest of my script stuff that would do it for you and return a JSON output (or whatever format you wanted really). All you'd need to do is go to the url and maybe add the promo page url as a variable..
![adaliabooks](https://images.gog.com/c90963e355fe1295789b379c4a4da768cbe394dc8b4c54439a31b01bfa2febc8_forum_avatar.jpg)
adaliabooks
"Vell, Zaphod's just zis guy, you know?"
Registered: Jun 2013
From United Kingdom
Posted March 17, 2016
![avatar](http://images.gog.com/8233fa4d06abcaf2c477cc3de7d65efd5dda42dc05cfecc5c282d620f57284b3_avm.jpg)
I suppose for what you want you needn't even mess around with the Angular JS as you could just pull the values you want from the html using Javascript or JQuery.
If you need a hand just let me know and I'll see if I can help :)
![Johny.GOG](https://images.gog.com/99c8c43498e075fae7b4eb220ad40d785a41b4f9284ddc8c1607ed670dd28325_forum_avatar.jpg)
Johny.GOG
☕️
GOG.com Team
Registered: Dec 2014
From Poland
Posted March 18, 2016
Paste this in your browsers console on promo page:
for (product of gogData.promoProducts) {
console.log(product.title + ': ' + product.price.amount);
}
I don't know how well that fits your needs, but maybe it will somehow guide you. :) You can retrieve that data from the HTML source code too - search for gogData.
edit: Adalia's way is also good for owned/not owned games. :)
for (product of gogData.promoProducts) {
console.log(product.title + ': ' + product.price.amount);
}
I don't know how well that fits your needs, but maybe it will somehow guide you. :) You can retrieve that data from the HTML source code too - search for gogData.
edit: Adalia's way is also good for owned/not owned games. :)
Post edited March 18, 2016 by Johny.
![adaliabooks](https://images.gog.com/c90963e355fe1295789b379c4a4da768cbe394dc8b4c54439a31b01bfa2febc8_forum_avatar.jpg)
adaliabooks
"Vell, Zaphod's just zis guy, you know?"
Registered: Jun 2013
From United Kingdom
Posted March 18, 2016
![avatar](http://images.gog.com/3d50cc3d3c8846da1801ff1849818e3fc082a528fcf1bde8e3f917b30bcf3ff2_avm.jpg)
for (product of gogData.promoProducts) {
console.log(product.title + ': ' + product.price.amount);
}
I don't know how well that fits your needs, but maybe it will somehow guide you. :) You can retrieve that data from the HTML source code too - search for gogData.
edit: Adalia's way is also good for owned/not owned games. :)
Thinking about it I overcomplicated it way too much, if all you want is the name and the price (as if you had copy and pasted it) there are much easier ways to do it then what I originally suggested.
My way was more for if you wanted to do some further processing on it in code (or pass the info back to the page, not really useful or relevant in this case).
![eiii](https://images.gog.com/8233fa4d06abcaf2c477cc3de7d65efd5dda42dc05cfecc5c282d620f57284b3_forum_avatar.jpg)
eiii
#%&@#%
Registered: Dec 2013
From San Marino
Posted March 18, 2016
Indeed, it's already embedded into the original URL. What a disgrace! I was just too blind. Not sure where I was looking the last time, probably only in the two .js files.
Thanks for your help, both of you!
A few lines of Python do the job for me:
import json
from lxml import html
import re
import requests
page = requests.get('https://www.gog.com/promo/weekly_staff_picks_git_gud_140314')
tree = html.fromstring(page.content)
script = tree.xpath('//script/text()')
m = re.match('^\n *var gogData = ({.*});\n', script[0])
j = json.loads(m.group(1))
for g in j['promoProducts']:
print(g['price']['amount'], g['slug'])
^^ That last line should be indented, but the forum software eats the leading spaces.
I just have started to learn Python so there's probably an easier way and the matching is ugly and not very robust, but at least it works. :)
Now I have to find out how to construct the cookies to change the language and currency and what the difference between price amount and price finalAmount is. But that's for tomorrow or so.
Edit: Cookie construction solved. :)
Johny.: Paste this in your browsers console on promo page:
for (product of gogData.promoProducts) {
console.log(product.title + ': ' + product.price.amount);
} That also works, nice. And it's much easier.
I still prefer the "browser free" version as I can combine it with other scripts when needed, but I definitely have to learn more about how to hack around in the browser. :)
Thanks for your help, both of you!
A few lines of Python do the job for me:
import json
from lxml import html
import re
import requests
page = requests.get('https://www.gog.com/promo/weekly_staff_picks_git_gud_140314')
tree = html.fromstring(page.content)
script = tree.xpath('//script/text()')
m = re.match('^\n *var gogData = ({.*});\n', script[0])
j = json.loads(m.group(1))
for g in j['promoProducts']:
print(g['price']['amount'], g['slug'])
^^ That last line should be indented, but the forum software eats the leading spaces.
I just have started to learn Python so there's probably an easier way and the matching is ugly and not very robust, but at least it works. :)
Now I have to find out how to construct the cookies to change the language and currency and what the difference between price amount and price finalAmount is. But that's for tomorrow or so.
Edit: Cookie construction solved. :)
![avatar](http://images.gog.com/3d50cc3d3c8846da1801ff1849818e3fc082a528fcf1bde8e3f917b30bcf3ff2_avm.jpg)
for (product of gogData.promoProducts) {
console.log(product.title + ': ' + product.price.amount);
}
I still prefer the "browser free" version as I can combine it with other scripts when needed, but I definitely have to learn more about how to hack around in the browser. :)
Post edited March 18, 2016 by eiii