Jump to content



Photo

Finding Text Similar + Clicking Element


  • Please log in to reply
7 replies to this topic

#1 jackg904

jackg904

    Member

  • Members
  • PipPip
  • 13 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Professional Edition

Posted 10 July 2018 - 10:43 AM

Racking my brains here, am new to UBot and have read a bunch of things- but still having difficulties.

I'm trying to have the bot find a text thats similar to an entered result, then click that element if it's there..

I can't seem to get that to work though- only exact matches somewhat "work" and even then- the element isn't actually navigated too.

 

I borrowed code from an old thread and am trying to modify it to do what I need. 

 

Here's my code:

navigate("http://ratemds.com","Wait")
type text(<name="text">,"ranga krishna","Standard")
click(<class="btn btn-default">,"Left Click","No")
set(#offset,0,"Global")
clear list(%num_results)
add list to list(%num_results,$scrape attribute(<data-reactid=".1xuzrq8sfms.3:$2060729.1">,"innertext"),"Delete","Global")
loop($list total(%num_results)) {
    set(#cur_title,$scrape attribute($element offset($element child(<data-reactid=".1xuzrq8sfms.3:$2060729.1">),#offset),"innertext"),"Global")
    if($contains(#cur_title,"Ranga Chelva Krishna")) {
        then {
            alert(#cur_title)
            set(#serp_id,$find regular expression($scrape attribute($element offset($element child($element child(<data-reactid=".1xuzrq8sfms.3:$2060729.1">)),#offset),"outerhtml"),"(?<=h\\=\\\").*?(?=\\\")"),"Global")
            click(<h=#serp_id>,"Left Click","No")
            alert("DONE")
            stop script
        }
        else {
        }
    }
    increment(#offset)
}

Any help/tips/etc is appreciated



#2 jackg904

jackg904

    Member

  • Members
  • PipPip
  • 13 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Professional Edition

Posted 10 July 2018 - 01:46 PM

Also tried: 

set(#offset,0,"Global")
set(#INPUT Keyword,"Ranga Chelva Krishna","Global")
clear list(%RESULTS)
add list to list(%RESULTS,$scrape attribute(<data-reactid=".1xuzrq8sfms.3:$2060729.1">,"fullhref"),"Delete","Global")
set(#RESULTS Row,0,"Global")
loop($list total(%RESULTS)) {
    if($contains($list item(%RESULTS,#RESULTS Row),#INPUT Keyword)) {
        then {
            click(<href=#INPUT Keyword>,"Left Click","No")
            wait for browser event("Page Loaded",10)
            wait(25)
        }
        else {
        }
    }
    increment(#RESULTS Row)

But it's not scraping the proper results page, just the home URL.



#3 hare ram

hare ram

    Advanced Member

  • Members
  • PipPipPip
  • 82 posts
  • LocationNew Delhi
  • OS:Windows 10
  • Total Memory:8Gb
  • Framework:v4.0
  • License:Professional Edition

Posted 11 July 2018 - 12:46 AM

Try this for scraping each url in a search page after that you can set what you want to match the record::--
add list to list(%num_results,$scrape attribute(<class="search-item-doctor-link">,"fullhref"),"Delete","Global")
 

Edited by hare ram, 11 July 2018 - 12:53 AM.


#4 HelloInsomnia

HelloInsomnia

    Advanced Member

  • Moderators
  • 2938 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 11 July 2018 - 02:15 PM

Is this what you're going for?

navigate("http://ratemds.com","Wait")
type text(<name="text">,"ranga krishna","Standard")
click(<class="btn btn-default">,"Left Click","No")
set(#offset,0,"Global")
clear list(%results)
add list to list(%results,$scrape attribute(<class="search-item-doctor-link">,"href"),"Delete","Global")
loop($list total(%results)) {
    navigate("https://www.ratemds.com{$next list item(%results)}","Wait")
    alert("scrape page here or do whatever")
    wait(2)
}


#5 jackg904

jackg904

    Member

  • Members
  • PipPip
  • 13 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Professional Edition

Posted 12 July 2018 - 08:01 AM

 

Is this what you're going for?

navigate("http://ratemds.com","Wait")
type text(<name="text">,"ranga krishna","Standard")
click(<class="btn btn-default">,"Left Click","No")
set(#offset,0,"Global")
clear list(%results)
add list to list(%results,$scrape attribute(<class="search-item-doctor-link">,"href"),"Delete","Global")
loop($list total(%results)) {
    navigate("https://www.ratemds.com{$next list item(%results)}","Wait")
    alert("scrape page here or do whatever")
    wait(2)
}

Not quite-

You got it to navigate where I wanted though- so that makes me happy!

I'm trying to have it look at all the "doctors" on the page, and click the most similar to what is entered, so if Ranga Krishna is entered it picks Ranga Chelva Krishna(the first most similar one)



#6 HelloInsomnia

HelloInsomnia

    Advanced Member

  • Moderators
  • 2938 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 12 July 2018 - 09:16 AM

Not quite-

You got it to navigate where I wanted though- so that makes me happy!

I'm trying to have it look at all the "doctors" on the page, and click the most similar to what is entered, so if Ranga Krishna is entered it picks Ranga Chelva Krishna(the first most similar one)

 

Okay I see, you can use Python to do that.

 

Basically, this will scrape the names, then use Python to match the names and see how similar each one of them is. Then it finds the highest match and clicks on that doctor.

navigate("http://ratemds.com","Wait")
set(#inputName,"ranga krishna","Global")
type text(<name="text">,#inputName,"Standard")
click(<class="btn btn-default">,"Left Click","No")
clear list(%names)
add list to list(%names,$scrape attribute(<class="search-item-doctor-link">,"innertext"),"Delete","Global")
clear table(&nameMatch)
set(#row,0,"Global")
loop($list total(%names)) {
    set(#curName,$next list item(%names),"Global")
    set(#normalizedMatch,$run python with result("from difflib import SequenceMatcher
name1 = \'{#inputName}\'
name2 = \'{#curName}\'
SequenceMatcher(a=name1,b=name2).ratio()"),"Global")
    set table cell(&nameMatch,#row,0,#curName)
    set table cell(&nameMatch,#row,1,$multiply(#normalizedMatch,100))
    increment(#row)
}
set(#row,1,"Global")
set(#highestScore,$table cell(&nameMatch,0,1),"Global")
set(#highestScoreOffset,0,"Global")
loop($subtract($list total(%names),1)) {
    if($comparison($table cell(&nameMatch,#row,1),"> Greater than",#highestScore)) {
        then {
            set(#highestScore,$table cell(&nameMatch,#row,1),"Global")
            set(#highestScoreOffset,#row,"Global")
        }
        else {
        }
    }
    increment(#row)
}
click(<class="search-item-doctor-link">,"Left Click","No")


#7 jackg904

jackg904

    Member

  • Members
  • PipPip
  • 13 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Professional Edition

Posted 12 July 2018 - 09:52 AM

 

Okay I see, you can use Python to do that.

 

Basically, this will scrape the names, then use Python to match the names and see how similar each one of them is. Then it finds the highest match and clicks on that doctor.

navigate("http://ratemds.com","Wait")
set(#inputName,"ranga krishna","Global")
type text(<name="text">,#inputName,"Standard")
click(<class="btn btn-default">,"Left Click","No")
clear list(%names)
add list to list(%names,$scrape attribute(<class="search-item-doctor-link">,"innertext"),"Delete","Global")
clear table(&nameMatch)
set(#row,0,"Global")
loop($list total(%names)) {
    set(#curName,$next list item(%names),"Global")
    set(#normalizedMatch,$run python with result("from difflib import SequenceMatcher
name1 = \'{#inputName}\'
name2 = \'{#curName}\'
SequenceMatcher(a=name1,b=name2).ratio()"),"Global")
    set table cell(&nameMatch,#row,0,#curName)
    set table cell(&nameMatch,#row,1,$multiply(#normalizedMatch,100))
    increment(#row)
}
set(#row,1,"Global")
set(#highestScore,$table cell(&nameMatch,0,1),"Global")
set(#highestScoreOffset,0,"Global")
loop($subtract($list total(%names),1)) {
    if($comparison($table cell(&nameMatch,#row,1),"> Greater than",#highestScore)) {
        then {
            set(#highestScore,$table cell(&nameMatch,#row,1),"Global")
            set(#highestScoreOffset,#row,"Global")
        }
        else {
        }
    }
    increment(#row)
}
click(<class="search-item-doctor-link">,"Left Click","No")

Wow!

Okay that's really cool- thank you so much.

Going to play around and try to exactly understand the code behind this so I don't ask anymore stupid questions.

Cheers mate. 



#8 jackg904

jackg904

    Member

  • Members
  • PipPip
  • 13 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Professional Edition

Posted 31 July 2018 - 01:56 PM

 

Okay I see, you can use Python to do that.

 

Basically, this will scrape the names, then use Python to match the names and see how similar each one of them is. Then it finds the highest match and clicks on that doctor.

navigate("http://ratemds.com","Wait")
set(#inputName,"ranga krishna","Global")
type text(<name="text">,#inputName,"Standard")
click(<class="btn btn-default">,"Left Click","No")
clear list(%names)
add list to list(%names,$scrape attribute(<class="search-item-doctor-link">,"innertext"),"Delete","Global")
clear table(&nameMatch)
set(#row,0,"Global")
loop($list total(%names)) {
    set(#curName,$next list item(%names),"Global")
    set(#normalizedMatch,$run python with result("from difflib import SequenceMatcher
name1 = \'{#inputName}\'
name2 = \'{#curName}\'
SequenceMatcher(a=name1,b=name2).ratio()"),"Global")
    set table cell(&nameMatch,#row,0,#curName)
    set table cell(&nameMatch,#row,1,$multiply(#normalizedMatch,100))
    increment(#row)
}
set(#row,1,"Global")
set(#highestScore,$table cell(&nameMatch,0,1),"Global")
set(#highestScoreOffset,0,"Global")
loop($subtract($list total(%names),1)) {
    if($comparison($table cell(&nameMatch,#row,1),"> Greater than",#highestScore)) {
        then {
            set(#highestScore,$table cell(&nameMatch,#row,1),"Global")
            set(#highestScoreOffset,#row,"Global")
        }
        else {
        }
    }
    increment(#row)
}
click(<class="search-item-doctor-link">,"Left Click","No")

I'm looking at debugger as I'm modifying this to be used for google search and it doesn't appear to be sorting based on value, and isn't navigating.

Same exact code using "class "r" for google, but it's not working by any stretch.

Any ideas?






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users