Author Topic: RoboB - GetElementByClassName  (Read 1635 times)

0 Members and 1 Guest are viewing this topic.

oswalsh

  • Jr. Member
  • **
  • Posts: 2
  • Karma: 0
    • View Profile
RoboB - GetElementByClassName
« on: July 03, 2015, 10:24:27 AM »
Hey,

I just started messing around with Robo Browser, and its awesome! However I'm trying to get it to read the news, and on the CBC, the news is contained in <div class="story-content">. Is there a way to get an element by class name?

I'm not sure how to use regex to match a single class name, when I try things like (?:^|\W)story-content(?:$|\W), I get all the text from the page, though I would think this would be the way to do it.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: RoboB - GetElementByClassName
« Reply #1 on: July 03, 2015, 10:52:02 AM »
I can't check this without knowing which specific web page you're using (cbc.ca/news didn't seem to have any divs with that class name) but I think you should be able to use the RoboB.ElementRegex action, like so:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.5.0-->
<command id="688" name="Get story content class content" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>RoboB.Select</cmdType>
    <params>
      <param>cbc</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>RoboB.Navigate</cmdType>
    <params>
      <param>YOUR URL</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>RoboB.Wait</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>RoboB.Show</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>RoboB.ElementRegex</cmdType>
    <params>
      <param>div</param>
      <param>class="story-content"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>RoboB.GetHTML</cmdType>
    <params />
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>RegExTool.Open</cmdType>
    <params>
      <param>True</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Get story content class content</phrase>
</command>
« Last Edit: July 03, 2015, 11:38:03 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: RoboB - GetElementByClassName
« Reply #2 on: July 03, 2015, 12:09:00 PM »
@Nime5ter that probably won't quite work because it will select the first parent div that contains this string anywhere in it.  Usually we need to specify the regex pattern for the beginning of the div's string using ^ or match at the end of the string using $.

So the pattern should probably look something like this:

Code: [Select]
^<div\sclass="story-content">

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: RoboB - GetElementByClassName
« Reply #3 on: July 03, 2015, 01:15:18 PM »
Ah yes, thanks. An important clarification. You've mentioned this before, I just keep forgetting. :)
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

oswalsh

  • Jr. Member
  • **
  • Posts: 2
  • Karma: 0
    • View Profile
Re: RoboB - GetElementByClassName
« Reply #4 on: July 05, 2015, 03:10:08 PM »
Just got back to playing with this, it works perfectly! Thanks you two.