Using python regular expresions to separate a string












0















I'm trying to get some images from an Amazon product page, I was able to extract all the images from the page in a single string but my knowledge of regular expressions is not that good for being able to separate it different URL's.



My goal is to get an array/list that contains all of the images that have "hiRes", for example, this one.



https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL.SL1500.jpg



Here is the complete string



All the images are under the 'colorImage' subdivision.



P.when('A').register("ImageBlockATF", function(A){

var data = {

'colorImages': { 'initial': [{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41vopqQJxiL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41vopqQJxiL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX355_.jpg":[219,355],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX450_.jpg":[278,450],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX425_.jpg":[263,425],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX466_.jpg":[288,466],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX522_.jpg":[323,522],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX569_.jpg":[352,569],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX679_.jpg":[420,679]},"variant":"MAIN","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41gksdhlW%2BL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41gksdhlW%2BL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX355_.jpg":[215,355],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX450_.jpg":[272,450],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX425_.jpg":[257,425],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX466_.jpg":[282,466],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX522_.jpg":[315,522],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX569_.jpg":[344,569],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX679_.jpg":[410,679]},"variant":"PT01","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41LaWXfiG5L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41LaWXfiG5L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX355_.jpg":[217,355],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX450_.jpg":[275,450],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX425_.jpg":[260,425],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX466_.jpg":[285,466],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX522_.jpg":[319,522],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX569_.jpg":[348,569],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX679_.jpg":[415,679]},"variant":"PT02","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41f4nUmawdL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41f4nUmawdL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX355_.jpg":[250,355],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX450_.jpg":[316,450],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX425_.jpg":[299,425],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX466_.jpg":[328,466],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX522_.jpg":[367,522],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX569_.jpg":[400,569],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX679_.jpg":[478,679]},"variant":"PT03","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/51dH0wiIHjL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/51dH0wiIHjL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX355_.jpg":[266,355],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX450_.jpg":[338,450],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX425_.jpg":[319,425],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX466_.jpg":[350,466],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX522_.jpg":[392,522],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX569_.jpg":[427,569],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX679_.jpg":[509,679]},"variant":"PT04","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/31RVniM5g2L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/31RVniM5g2L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SY355_.jpg":[355,355],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SY450_.jpg":[450,450],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX425_.jpg":[425,425],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX466_.jpg":[466,466],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX522_.jpg":[522,522],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX569_.jpg":[569,569],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX679_.jpg":[679,679]},"variant":"PT05","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/31593M2oY0L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/31593M2oY0L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SY355_.jpg":[355,355],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SY450_.jpg":[450,450],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX425_.jpg":[425,425],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX466_.jpg":[466,466],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX522_.jpg":[522,522],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX569_.jpg":[569,569],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX679_.jpg":[679,679]},"variant":"PT06","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41EChsg2DAL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41EChsg2DAL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX355_.jpg":[251,355],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX450_.jpg":[318,450],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX425_.jpg":[301,425],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX466_.jpg":[330,466],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX522_.jpg":[369,522],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX569_.jpg":[402,569],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX679_.jpg":[480,679]},"variant":"PT07","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41LXguq9kAL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41LXguq9kAL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX355_.jpg":[250,355],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX450_.jpg":[316,450],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX425_.jpg":[299,425],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX466_.jpg":[328,466],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX522_.jpg":[367,522],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX569_.jpg":[400,569],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX679_.jpg":[477,679]},"variant":"PT08","lowRes":null}]},

'colorToAsin': {'initial': {}},

'holderRatio': 1.0,

'holderMaxHeight': 700,

'heroImage': {'initial': },

'heroVideo': {'initial': },

'spin360ColorData': {'initial': {}},

'spin360ColorEnabled': {'initial': 0},

'spin360ConfigEnabled': false,

'spin360LazyLoadEnabled': false,

'playVideoInImmersiveView':'false',

'tabbedImmersiveViewTreatment':'T2',

'totalVideoCount':'0',

'videoIngressATFSlateThumbURL':'',

'mediaTypeCount':'0',

'atfEnhancedHoverOverlay' : true,

'winningAsin': 'B07HGMDY4T',

'weblabs' : {},

'aibExp3Layout' : 1,

'aibRuleName' : 'R17',

'acEnabled' : false

};

A.trigger('P.AboveTheFold'); // trigger ATF event.

return data;

});









share|improve this question

























  • Perhaps I am missing something in your example, but data is a dictionary that you can reference directly for your images (e.g. data['colorImages']['initial'][0]['hiRes']). There is no string to apply regex to.

    – Studybuffalo
    Nov 23 '18 at 14:37











  • Sorry if i was not clear enough. That block of code is a string itself, which i extracted from the Amazon page with (using XPath) //script[contains(., "ImageBlockATF")]/text() The example is an extraction i got from this product amazon.com/Dell-Inspiron-15-Gaming-Laptop/dp/B07HGMDY4T/…

    – Manuel
    Nov 23 '18 at 15:54


















0















I'm trying to get some images from an Amazon product page, I was able to extract all the images from the page in a single string but my knowledge of regular expressions is not that good for being able to separate it different URL's.



My goal is to get an array/list that contains all of the images that have "hiRes", for example, this one.



https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL.SL1500.jpg



Here is the complete string



All the images are under the 'colorImage' subdivision.



P.when('A').register("ImageBlockATF", function(A){

var data = {

'colorImages': { 'initial': [{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41vopqQJxiL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41vopqQJxiL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX355_.jpg":[219,355],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX450_.jpg":[278,450],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX425_.jpg":[263,425],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX466_.jpg":[288,466],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX522_.jpg":[323,522],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX569_.jpg":[352,569],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX679_.jpg":[420,679]},"variant":"MAIN","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41gksdhlW%2BL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41gksdhlW%2BL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX355_.jpg":[215,355],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX450_.jpg":[272,450],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX425_.jpg":[257,425],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX466_.jpg":[282,466],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX522_.jpg":[315,522],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX569_.jpg":[344,569],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX679_.jpg":[410,679]},"variant":"PT01","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41LaWXfiG5L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41LaWXfiG5L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX355_.jpg":[217,355],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX450_.jpg":[275,450],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX425_.jpg":[260,425],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX466_.jpg":[285,466],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX522_.jpg":[319,522],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX569_.jpg":[348,569],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX679_.jpg":[415,679]},"variant":"PT02","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41f4nUmawdL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41f4nUmawdL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX355_.jpg":[250,355],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX450_.jpg":[316,450],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX425_.jpg":[299,425],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX466_.jpg":[328,466],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX522_.jpg":[367,522],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX569_.jpg":[400,569],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX679_.jpg":[478,679]},"variant":"PT03","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/51dH0wiIHjL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/51dH0wiIHjL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX355_.jpg":[266,355],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX450_.jpg":[338,450],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX425_.jpg":[319,425],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX466_.jpg":[350,466],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX522_.jpg":[392,522],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX569_.jpg":[427,569],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX679_.jpg":[509,679]},"variant":"PT04","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/31RVniM5g2L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/31RVniM5g2L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SY355_.jpg":[355,355],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SY450_.jpg":[450,450],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX425_.jpg":[425,425],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX466_.jpg":[466,466],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX522_.jpg":[522,522],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX569_.jpg":[569,569],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX679_.jpg":[679,679]},"variant":"PT05","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/31593M2oY0L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/31593M2oY0L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SY355_.jpg":[355,355],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SY450_.jpg":[450,450],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX425_.jpg":[425,425],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX466_.jpg":[466,466],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX522_.jpg":[522,522],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX569_.jpg":[569,569],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX679_.jpg":[679,679]},"variant":"PT06","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41EChsg2DAL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41EChsg2DAL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX355_.jpg":[251,355],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX450_.jpg":[318,450],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX425_.jpg":[301,425],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX466_.jpg":[330,466],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX522_.jpg":[369,522],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX569_.jpg":[402,569],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX679_.jpg":[480,679]},"variant":"PT07","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41LXguq9kAL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41LXguq9kAL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX355_.jpg":[250,355],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX450_.jpg":[316,450],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX425_.jpg":[299,425],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX466_.jpg":[328,466],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX522_.jpg":[367,522],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX569_.jpg":[400,569],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX679_.jpg":[477,679]},"variant":"PT08","lowRes":null}]},

'colorToAsin': {'initial': {}},

'holderRatio': 1.0,

'holderMaxHeight': 700,

'heroImage': {'initial': },

'heroVideo': {'initial': },

'spin360ColorData': {'initial': {}},

'spin360ColorEnabled': {'initial': 0},

'spin360ConfigEnabled': false,

'spin360LazyLoadEnabled': false,

'playVideoInImmersiveView':'false',

'tabbedImmersiveViewTreatment':'T2',

'totalVideoCount':'0',

'videoIngressATFSlateThumbURL':'',

'mediaTypeCount':'0',

'atfEnhancedHoverOverlay' : true,

'winningAsin': 'B07HGMDY4T',

'weblabs' : {},

'aibExp3Layout' : 1,

'aibRuleName' : 'R17',

'acEnabled' : false

};

A.trigger('P.AboveTheFold'); // trigger ATF event.

return data;

});









share|improve this question

























  • Perhaps I am missing something in your example, but data is a dictionary that you can reference directly for your images (e.g. data['colorImages']['initial'][0]['hiRes']). There is no string to apply regex to.

    – Studybuffalo
    Nov 23 '18 at 14:37











  • Sorry if i was not clear enough. That block of code is a string itself, which i extracted from the Amazon page with (using XPath) //script[contains(., "ImageBlockATF")]/text() The example is an extraction i got from this product amazon.com/Dell-Inspiron-15-Gaming-Laptop/dp/B07HGMDY4T/…

    – Manuel
    Nov 23 '18 at 15:54
















0












0








0








I'm trying to get some images from an Amazon product page, I was able to extract all the images from the page in a single string but my knowledge of regular expressions is not that good for being able to separate it different URL's.



My goal is to get an array/list that contains all of the images that have "hiRes", for example, this one.



https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL.SL1500.jpg



Here is the complete string



All the images are under the 'colorImage' subdivision.



P.when('A').register("ImageBlockATF", function(A){

var data = {

'colorImages': { 'initial': [{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41vopqQJxiL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41vopqQJxiL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX355_.jpg":[219,355],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX450_.jpg":[278,450],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX425_.jpg":[263,425],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX466_.jpg":[288,466],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX522_.jpg":[323,522],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX569_.jpg":[352,569],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX679_.jpg":[420,679]},"variant":"MAIN","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41gksdhlW%2BL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41gksdhlW%2BL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX355_.jpg":[215,355],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX450_.jpg":[272,450],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX425_.jpg":[257,425],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX466_.jpg":[282,466],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX522_.jpg":[315,522],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX569_.jpg":[344,569],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX679_.jpg":[410,679]},"variant":"PT01","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41LaWXfiG5L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41LaWXfiG5L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX355_.jpg":[217,355],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX450_.jpg":[275,450],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX425_.jpg":[260,425],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX466_.jpg":[285,466],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX522_.jpg":[319,522],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX569_.jpg":[348,569],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX679_.jpg":[415,679]},"variant":"PT02","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41f4nUmawdL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41f4nUmawdL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX355_.jpg":[250,355],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX450_.jpg":[316,450],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX425_.jpg":[299,425],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX466_.jpg":[328,466],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX522_.jpg":[367,522],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX569_.jpg":[400,569],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX679_.jpg":[478,679]},"variant":"PT03","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/51dH0wiIHjL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/51dH0wiIHjL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX355_.jpg":[266,355],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX450_.jpg":[338,450],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX425_.jpg":[319,425],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX466_.jpg":[350,466],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX522_.jpg":[392,522],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX569_.jpg":[427,569],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX679_.jpg":[509,679]},"variant":"PT04","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/31RVniM5g2L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/31RVniM5g2L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SY355_.jpg":[355,355],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SY450_.jpg":[450,450],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX425_.jpg":[425,425],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX466_.jpg":[466,466],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX522_.jpg":[522,522],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX569_.jpg":[569,569],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX679_.jpg":[679,679]},"variant":"PT05","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/31593M2oY0L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/31593M2oY0L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SY355_.jpg":[355,355],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SY450_.jpg":[450,450],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX425_.jpg":[425,425],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX466_.jpg":[466,466],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX522_.jpg":[522,522],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX569_.jpg":[569,569],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX679_.jpg":[679,679]},"variant":"PT06","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41EChsg2DAL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41EChsg2DAL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX355_.jpg":[251,355],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX450_.jpg":[318,450],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX425_.jpg":[301,425],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX466_.jpg":[330,466],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX522_.jpg":[369,522],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX569_.jpg":[402,569],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX679_.jpg":[480,679]},"variant":"PT07","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41LXguq9kAL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41LXguq9kAL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX355_.jpg":[250,355],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX450_.jpg":[316,450],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX425_.jpg":[299,425],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX466_.jpg":[328,466],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX522_.jpg":[367,522],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX569_.jpg":[400,569],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX679_.jpg":[477,679]},"variant":"PT08","lowRes":null}]},

'colorToAsin': {'initial': {}},

'holderRatio': 1.0,

'holderMaxHeight': 700,

'heroImage': {'initial': },

'heroVideo': {'initial': },

'spin360ColorData': {'initial': {}},

'spin360ColorEnabled': {'initial': 0},

'spin360ConfigEnabled': false,

'spin360LazyLoadEnabled': false,

'playVideoInImmersiveView':'false',

'tabbedImmersiveViewTreatment':'T2',

'totalVideoCount':'0',

'videoIngressATFSlateThumbURL':'',

'mediaTypeCount':'0',

'atfEnhancedHoverOverlay' : true,

'winningAsin': 'B07HGMDY4T',

'weblabs' : {},

'aibExp3Layout' : 1,

'aibRuleName' : 'R17',

'acEnabled' : false

};

A.trigger('P.AboveTheFold'); // trigger ATF event.

return data;

});









share|improve this question
















I'm trying to get some images from an Amazon product page, I was able to extract all the images from the page in a single string but my knowledge of regular expressions is not that good for being able to separate it different URL's.



My goal is to get an array/list that contains all of the images that have "hiRes", for example, this one.



https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL.SL1500.jpg



Here is the complete string



All the images are under the 'colorImage' subdivision.



P.when('A').register("ImageBlockATF", function(A){

var data = {

'colorImages': { 'initial': [{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41vopqQJxiL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41vopqQJxiL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX355_.jpg":[219,355],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX450_.jpg":[278,450],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX425_.jpg":[263,425],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX466_.jpg":[288,466],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX522_.jpg":[323,522],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX569_.jpg":[352,569],"https://images-na.ssl-images-amazon.com/images/I/715ljjcwtbL._SX679_.jpg":[420,679]},"variant":"MAIN","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41gksdhlW%2BL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41gksdhlW%2BL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX355_.jpg":[215,355],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX450_.jpg":[272,450],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX425_.jpg":[257,425],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX466_.jpg":[282,466],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX522_.jpg":[315,522],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX569_.jpg":[344,569],"https://images-na.ssl-images-amazon.com/images/I/71wL0h3T8ZL._SX679_.jpg":[410,679]},"variant":"PT01","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41LaWXfiG5L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41LaWXfiG5L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX355_.jpg":[217,355],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX450_.jpg":[275,450],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX425_.jpg":[260,425],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX466_.jpg":[285,466],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX522_.jpg":[319,522],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX569_.jpg":[348,569],"https://images-na.ssl-images-amazon.com/images/I/71R48178vZL._SX679_.jpg":[415,679]},"variant":"PT02","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41f4nUmawdL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41f4nUmawdL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX355_.jpg":[250,355],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX450_.jpg":[316,450],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX425_.jpg":[299,425],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX466_.jpg":[328,466],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX522_.jpg":[367,522],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX569_.jpg":[400,569],"https://images-na.ssl-images-amazon.com/images/I/81BZF8-hNpL._SX679_.jpg":[478,679]},"variant":"PT03","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/51dH0wiIHjL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/51dH0wiIHjL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX355_.jpg":[266,355],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX450_.jpg":[338,450],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX425_.jpg":[319,425],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX466_.jpg":[350,466],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX522_.jpg":[392,522],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX569_.jpg":[427,569],"https://images-na.ssl-images-amazon.com/images/I/A1YDIIAWSWL._SX679_.jpg":[509,679]},"variant":"PT04","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/31RVniM5g2L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/31RVniM5g2L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SY355_.jpg":[355,355],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SY450_.jpg":[450,450],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX425_.jpg":[425,425],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX466_.jpg":[466,466],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX522_.jpg":[522,522],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX569_.jpg":[569,569],"https://images-na.ssl-images-amazon.com/images/I/61qFqipGhCL._SX679_.jpg":[679,679]},"variant":"PT05","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/31593M2oY0L._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/31593M2oY0L.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SY355_.jpg":[355,355],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SY450_.jpg":[450,450],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX425_.jpg":[425,425],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX466_.jpg":[466,466],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX522_.jpg":[522,522],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX569_.jpg":[569,569],"https://images-na.ssl-images-amazon.com/images/I/61C1UIQU7YL._SX679_.jpg":[679,679]},"variant":"PT06","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41EChsg2DAL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41EChsg2DAL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX355_.jpg":[251,355],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX450_.jpg":[318,450],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX425_.jpg":[301,425],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX466_.jpg":[330,466],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX522_.jpg":[369,522],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX569_.jpg":[402,569],"https://images-na.ssl-images-amazon.com/images/I/71QthPBNgLL._SX679_.jpg":[480,679]},"variant":"PT07","lowRes":null},{"hiRes":"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SL1500_.jpg","thumb":"https://images-na.ssl-images-amazon.com/images/I/41LXguq9kAL._SS40_.jpg","large":"https://images-na.ssl-images-amazon.com/images/I/41LXguq9kAL.jpg","main":{"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX355_.jpg":[250,355],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX450_.jpg":[316,450],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX425_.jpg":[299,425],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX466_.jpg":[328,466],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX522_.jpg":[367,522],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX569_.jpg":[400,569],"https://images-na.ssl-images-amazon.com/images/I/71xAVDnbRzL._SX679_.jpg":[477,679]},"variant":"PT08","lowRes":null}]},

'colorToAsin': {'initial': {}},

'holderRatio': 1.0,

'holderMaxHeight': 700,

'heroImage': {'initial': },

'heroVideo': {'initial': },

'spin360ColorData': {'initial': {}},

'spin360ColorEnabled': {'initial': 0},

'spin360ConfigEnabled': false,

'spin360LazyLoadEnabled': false,

'playVideoInImmersiveView':'false',

'tabbedImmersiveViewTreatment':'T2',

'totalVideoCount':'0',

'videoIngressATFSlateThumbURL':'',

'mediaTypeCount':'0',

'atfEnhancedHoverOverlay' : true,

'winningAsin': 'B07HGMDY4T',

'weblabs' : {},

'aibExp3Layout' : 1,

'aibRuleName' : 'R17',

'acEnabled' : false

};

A.trigger('P.AboveTheFold'); // trigger ATF event.

return data;

});






regex python-3.x web-scraping






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 13 '18 at 17:21









Wiktor Stribiżew

312k16132207




312k16132207










asked Nov 23 '18 at 13:34









ManuelManuel

686




686













  • Perhaps I am missing something in your example, but data is a dictionary that you can reference directly for your images (e.g. data['colorImages']['initial'][0]['hiRes']). There is no string to apply regex to.

    – Studybuffalo
    Nov 23 '18 at 14:37











  • Sorry if i was not clear enough. That block of code is a string itself, which i extracted from the Amazon page with (using XPath) //script[contains(., "ImageBlockATF")]/text() The example is an extraction i got from this product amazon.com/Dell-Inspiron-15-Gaming-Laptop/dp/B07HGMDY4T/…

    – Manuel
    Nov 23 '18 at 15:54





















  • Perhaps I am missing something in your example, but data is a dictionary that you can reference directly for your images (e.g. data['colorImages']['initial'][0]['hiRes']). There is no string to apply regex to.

    – Studybuffalo
    Nov 23 '18 at 14:37











  • Sorry if i was not clear enough. That block of code is a string itself, which i extracted from the Amazon page with (using XPath) //script[contains(., "ImageBlockATF")]/text() The example is an extraction i got from this product amazon.com/Dell-Inspiron-15-Gaming-Laptop/dp/B07HGMDY4T/…

    – Manuel
    Nov 23 '18 at 15:54



















Perhaps I am missing something in your example, but data is a dictionary that you can reference directly for your images (e.g. data['colorImages']['initial'][0]['hiRes']). There is no string to apply regex to.

– Studybuffalo
Nov 23 '18 at 14:37





Perhaps I am missing something in your example, but data is a dictionary that you can reference directly for your images (e.g. data['colorImages']['initial'][0]['hiRes']). There is no string to apply regex to.

– Studybuffalo
Nov 23 '18 at 14:37













Sorry if i was not clear enough. That block of code is a string itself, which i extracted from the Amazon page with (using XPath) //script[contains(., "ImageBlockATF")]/text() The example is an extraction i got from this product amazon.com/Dell-Inspiron-15-Gaming-Laptop/dp/B07HGMDY4T/…

– Manuel
Nov 23 '18 at 15:54







Sorry if i was not clear enough. That block of code is a string itself, which i extracted from the Amazon page with (using XPath) //script[contains(., "ImageBlockATF")]/text() The example is an extraction i got from this product amazon.com/Dell-Inspiron-15-Gaming-Laptop/dp/B07HGMDY4T/…

– Manuel
Nov 23 '18 at 15:54














1 Answer
1






active

oldest

votes


















1














If you want to stick with a regex solution, you could try a match like this: r'"hiRes":"(https.*?.jpg)"'



A quick explanation:




  • Match any string that starts with "hiRes":"https and finishes with .jpg"

  • Use a capturing group to get the actual URL (this assumes all URLs will start with https and end with .jpg


You could use the above regex with re.match or re.search to hopefully get what you are looking for. You should be able to extract you match groups out from here. See https://docs.python.org/3/library/re.html#match-objects id you need more details on this.






share|improve this answer
























  • Sorry for answering so late, i was busy for a couple of days. This worked perfectly!, ended up using re.findall('"hiRes":"(https.*?.jpg)"', images). Thanks for the help!

    – Manuel
    Nov 26 '18 at 18:19











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447699%2fusing-python-regular-expresions-to-separate-a-string%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














If you want to stick with a regex solution, you could try a match like this: r'"hiRes":"(https.*?.jpg)"'



A quick explanation:




  • Match any string that starts with "hiRes":"https and finishes with .jpg"

  • Use a capturing group to get the actual URL (this assumes all URLs will start with https and end with .jpg


You could use the above regex with re.match or re.search to hopefully get what you are looking for. You should be able to extract you match groups out from here. See https://docs.python.org/3/library/re.html#match-objects id you need more details on this.






share|improve this answer
























  • Sorry for answering so late, i was busy for a couple of days. This worked perfectly!, ended up using re.findall('"hiRes":"(https.*?.jpg)"', images). Thanks for the help!

    – Manuel
    Nov 26 '18 at 18:19
















1














If you want to stick with a regex solution, you could try a match like this: r'"hiRes":"(https.*?.jpg)"'



A quick explanation:




  • Match any string that starts with "hiRes":"https and finishes with .jpg"

  • Use a capturing group to get the actual URL (this assumes all URLs will start with https and end with .jpg


You could use the above regex with re.match or re.search to hopefully get what you are looking for. You should be able to extract you match groups out from here. See https://docs.python.org/3/library/re.html#match-objects id you need more details on this.






share|improve this answer
























  • Sorry for answering so late, i was busy for a couple of days. This worked perfectly!, ended up using re.findall('"hiRes":"(https.*?.jpg)"', images). Thanks for the help!

    – Manuel
    Nov 26 '18 at 18:19














1












1








1







If you want to stick with a regex solution, you could try a match like this: r'"hiRes":"(https.*?.jpg)"'



A quick explanation:




  • Match any string that starts with "hiRes":"https and finishes with .jpg"

  • Use a capturing group to get the actual URL (this assumes all URLs will start with https and end with .jpg


You could use the above regex with re.match or re.search to hopefully get what you are looking for. You should be able to extract you match groups out from here. See https://docs.python.org/3/library/re.html#match-objects id you need more details on this.






share|improve this answer













If you want to stick with a regex solution, you could try a match like this: r'"hiRes":"(https.*?.jpg)"'



A quick explanation:




  • Match any string that starts with "hiRes":"https and finishes with .jpg"

  • Use a capturing group to get the actual URL (this assumes all URLs will start with https and end with .jpg


You could use the above regex with re.match or re.search to hopefully get what you are looking for. You should be able to extract you match groups out from here. See https://docs.python.org/3/library/re.html#match-objects id you need more details on this.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 2:05









StudybuffaloStudybuffalo

33647




33647













  • Sorry for answering so late, i was busy for a couple of days. This worked perfectly!, ended up using re.findall('"hiRes":"(https.*?.jpg)"', images). Thanks for the help!

    – Manuel
    Nov 26 '18 at 18:19



















  • Sorry for answering so late, i was busy for a couple of days. This worked perfectly!, ended up using re.findall('"hiRes":"(https.*?.jpg)"', images). Thanks for the help!

    – Manuel
    Nov 26 '18 at 18:19

















Sorry for answering so late, i was busy for a couple of days. This worked perfectly!, ended up using re.findall('"hiRes":"(https.*?.jpg)"', images). Thanks for the help!

– Manuel
Nov 26 '18 at 18:19





Sorry for answering so late, i was busy for a couple of days. This worked perfectly!, ended up using re.findall('"hiRes":"(https.*?.jpg)"', images). Thanks for the help!

– Manuel
Nov 26 '18 at 18:19


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447699%2fusing-python-regular-expresions-to-separate-a-string%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...