jackg904 0 Posted July 10, 2018 Report Share Posted July 10, 2018 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 Quote Link to post Share on other sites
jackg904 0 Posted July 10, 2018 Author Report Share Posted July 10, 2018 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. Quote Link to post Share on other sites
hare ram 23 Posted July 11, 2018 Report Share Posted July 11, 2018 (edited) 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 July 11, 2018 by hare ram Quote Link to post Share on other sites
HelloInsomnia 1103 Posted July 11, 2018 Report Share Posted July 11, 2018 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) } Quote Link to post Share on other sites
jackg904 0 Posted July 12, 2018 Author Report Share Posted July 12, 2018 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) Quote Link to post Share on other sites
HelloInsomnia 1103 Posted July 12, 2018 Report Share Posted July 12, 2018 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") Quote Link to post Share on other sites
jackg904 0 Posted July 12, 2018 Author Report Share Posted July 12, 2018 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. Quote Link to post Share on other sites
jackg904 0 Posted July 31, 2018 Author Report Share Posted July 31, 2018 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? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.