Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All.

I am trying to scrapping data from website.

In some case if the data have been delete the website is change.

So I Use
appIE.document.getElementsByClassName("alert-block")


But I don't know how to identify if the class
("alert-block")
exits or not.

I have read the artical here


[^][^]

And they say that the

If MyObject Is Nothing Then  ' <--- This check always returns False


What I have tried:

If appIE.document.getElementsByClassName("alert-block") Is Nothing Then

'Do something1.
else
'do something2 here.
endif
Posted
Updated 16-Apr-18 23:54pm

1 solution

getElementsByClassName returns a collection. If no element can be found a collection with no items is returned. But it is still a collection object so that checking for Nothing will always fail. Instead check if the collection is empty or not by using the Count property:
VB
Set element = appIE.document.getElementsByClassName("alert-block")
If element.Count > 0
' Element exists and is not empty
Endif
 
Share this answer
 
Comments
hmanhha 17-Apr-18 21:32pm    
If user have do something then the data have been delete the IE will have the class "alert-block" and if user did not delete IE will not have this class.

So cannot use getElementByClassName("alert-block")
Jochen Arndt 18-Apr-18 3:03am    
I did not get what you want to tell me here.
My code tells you if the element exists (or not in the Else case). So where is the problem?
hmanhha 18-Apr-18 16:25pm    
I mean here is that. Normally web site have element with classname ("alert-block")
but obnomal it dont have and your code will have error. and how can I detect this obnomal situation when getelementbyClassName and getElementbyID.
Jochen Arndt 18-Apr-18 17:40pm    
What error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900