Simulate a click on a link on a web page

I'm trying to clear below webpage

http://www.houseoffraser.co.uk/Eliza+J+3/4+sleeve+ruched+waist+dress/165288648,default,pd.html

Stock data for each combination of colors and sizes is displayed only when a color or size is selected. In r, you can simulate this to get data.

So far I have been able to fix color and size

mcolour = toString(xpathSApply(page,'//ul[@class="colour-swatches-list toggle-panel"]//li[@title]',xmlGetAttr,"title")) size = xpathSApply(page,'//ul[@class="size-swatches-list toggle-panel"]//li[@data-size]',xmlGetAttr,"data-size") 

but I'm not sure how capture levels are for a combination of colors and sizes.

Please advice!

==================================================== =========== I could not find a new method, I did not miss anything?

 firefoxClass Generator for class "firefoxClass": Class fields: Name: exceptionTable javaWarMes javaDriver javaNavigate Class: matrix ANY ANY ANY Class Methods: "back", "callSuper", "close", "copy", "export", "field", "findElementByClassName", "findElementByCssSelector", "findElementById", "findElementByLinkText", "findElementByName", "findElementByPartialLinkText", "findElementByTagName", "findElementByXPath", "findElementsByClassName", "findElementsByCssSelector", "findElementsById", "findElementsByLinkText", "findElementsByName", "findElementsByPartialLinkText", "findElementsByTagName", "findElementsByXPath", "forward", "get", "getCapabilities", "getClass", "getCurrentUrl", "getPageSource", "getRefClass", "getTitle", "getVersion", "import", "initFields", "initialize", "initialize#exceptionClass", "printHtml", "refresh", "show", "show#envRefClass", "trace", "tryExc", "untrace", "usingMethods" Reference Superclasses: "exceptionClass", "envRefClass" 
+2
source share
2 answers

For a given pid product identifier, which you can clear from the page, you can get stock availability by requesting:

http://www.houseoffraser.co.uk/on/demandware.store/Sites-hof-Site/default/Product-UpdateQuantityList?pid=165288698&quantity=1

you donโ€™t even need to set cookies for this request. This returns the HTML and javascript snippet that is used to set the control on the page. Here is an example of a limited supply (currently 2, although I may have just bought them by accident):

http://www.houseoffraser.co.uk/on/demandware.store/Sites-hof-Site/default/Product-UpdateQuantityList?pid=165288648&quantity=1

You can get the quantity in stock either by parsing the availabilityMessage line or <select> .

The only step that I have not developed is to get the pid values โ€‹โ€‹and how to compare them with the descriptions, but all this should be on the page somewhere if it does not load using Ajax requests (where the stock data comes from).

You use the Chrome debugger / inspector, right?

0
source

Here is an example using relenium that you can easily expand and query for product colors:

 require(relenium) # More info: https://github.com/LluisRamon/relenium require(XML) firefox <- firefoxClass$new() # init browser firefox$get("http://www.houseoffraser.co.uk/Eliza+J+3/4+sleeve+ruched+waist+dress/165288648,default,pd.html") # open url sizes <- xpathSApply(htmlParse(firefox$getPageSource()), "//ul[@class='size-swatches-list toggle-panel']/li/a", xmlValue) # read available sizes stockMsg <- vector() # init stock message vector for (size in sizes) { # for each available size sizeLink <- firefox$findElementByXPath(sprintf("//ul[@class='size-swatches-list toggle-panel']/li[@data-size='%s']", size)) # focus size link sizeLink$click() # click size link stockMsg <- c(stockMsg, # and append stock message to stock message vector firefox$findElementByXPath("/html/body/div/div[3]/div/div/div[4]/div/div/div/div/form/div[4]/div[4]/div")$getText() ) } setNames(stockMsg, sizes) # name stock msg vector and print it # 8 10 # "in stock" "in stock" # 12 14 # "in stock" "in stock" # 16 18 # "in stock" "in stock, only 17 left" # 20 22 # "in stock, only 2 left" "in stock, only 2 left" # 24 26 # "Out of stock" "Out of stock" # 28 # "Out of stock" 
+1
source

All Articles