0

I have to read the comments on Linkedin, which shows only 10 comments at a time with a link "Show Previous Comment". I have 1000 comments so need to click the show previous comment 100 times to see all of them. I want to know how to use Rselenium to use "clickElement()" 100 times on the linkedin page. Afterward, I hope to export the comments to a spreadsheet or text file.

Here is the code

comments <- remDr$findElement(using = 'class name', "text")
comments$clickElement()

This enables me to click once but I need to click it 100 times.

josliber
  • 43,891
  • 12
  • 98
  • 133
  • 2
    Could you share the code you've developed so far to address this problem? We'll best be able to help you if you can point to a particular problem with your current code. – josliber Apr 26 '15 at 21:35
  • if I execute comments$clickElement ( ) manually then it execute once. What I'm looking for is to execute it 100 times using a function. – analytics3345 Apr 26 '15 at 21:56
  • 1
    Thanks for posting some code. Unfortunately we can't run this code because we don't have the object `remDr`. Could you post a reproducible example, meaning one where we can run the code and see the problem you're having? You can read [here](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for more details about reproducible examples. – josliber Apr 26 '15 at 22:07
  • Thanks for reply, I able to click the link using the above code. What I need to do is to click the link 100 times so basically repeat clickElement() 100 times. – analytics3345 Apr 26 '15 at 22:25
  • At present what I'm doing is running the code manually each time but it should be far easier to write a function saying do it 50 times or 100 times. Challenge I'm facing is integrating R function with this rselenium command. For data sets it is a lot easier. – analytics3345 Apr 26 '15 at 22:27
  • You could try `for (i in 1:100) { comments$clickElement() }`, which is an R for loop. However I have no idea if this works because I don't have access to `remDr`. Could you update your code to include `remDr`? – josliber Apr 26 '15 at 22:35
  • Thanks a lot I tweaked it a bit but the code worked perfectly. – analytics3345 Apr 26 '15 at 23:31
  • If you simply want to do it 100 times, `replicate(100, comments$clickElement())` is better than using a for loop. – Molx Apr 27 '15 at 01:25
  • @josilber Add that as an answer – Dason May 07 '15 at 17:00
  • @Molx I'm not sure it makes much of a difference here but it's probably more readable – Dason May 07 '15 at 17:02

0 Answers0