vba - How to break a loop when it is done? -
i've created scraper in vba in combination selenium parse different firm names webpage. page has traversed 56 more pages can reached using forward button. scraper able scrape data available in 57 pages of loop. however, issue i'm facing here script not able break out of loop when done collecting data. because used "do while true" condition in loop. should in condition script able break loop , quit browser when done? in advance.
here i've written far:
sub jscriptinjected_data() dim driver new chromedriver dim posts object, post object driver .get "http://registers.centralbank.ie/fundsearchresultspage.aspx?searchentity=fundserviceprovider&searchtype=name&searchtext=®isters=6%2c29%2c44%2c45&aspxautodetectcookiesupport=1" while true set posts = .findelementsbyclass("entitynamecolumn") each post in posts x = x + 1: cells(x, 1) = post.findelementbytag("a").text next post .findelementbyid("ctl00_cphregistersmasterpage_gvwsearchresults_ctl18_btnnext").click loop end driver.quit end sub
as gserg suggested, break out when posts nothing
- if api throws error when there's "no such element", handle it!
that do while true...loop
construct weird; if need infinite loop do...loop
:
do set posts = .findelementsbyclass("entitynamecolumn") '... on error resume next .findelementbyid("ctl00_cphregistersmasterpage_gvwsearchresults_ctl18_btnnext").click if err.number <> 0 exit on error goto 0 loop
Comments
Post a Comment