In the process of scraping data from a website, I use the following line of code:
a = eachmatch(Selector(".rank_view"), h.root)[1]
However, occasionally, the line throws the following error:
BoundsError: attempt to access 0-element Vector{HTMLNode} at index [1]
If I were to use an if-statement, how would I get my script to continue to the next iteration of my loop? I was hoping that I could use “if isempty(h.root)” but that does not work. How might I solve the stated problem?
I think you need to check if the match is empty, not the element:
matches = eachmatch(Selector(".rank_view"), h.root)
if isempty(matches)
continue # go back to the top of the enclosing loop
else
# do stuff with matches[1]
end