Get value from webpage (1 Viewer)

cpampas

Registered User.
Local time
Yesterday, 18:14
Joined
Jul 23, 2012
Messages
69
Hello,
I am beginner with extracting data via VBA from webpages, and still I could not find a solution to this :
my code gets all the values that I need except for this one :

<div class="value"><img src="/images/text.php?type=empresa&amp;field=telefone&amp;id_empresa=289251"></div>


Code:
Dim ie As Object ' InternetExplorer
Dim HTML    As HTMLDocument

' All elements
Dim elc   As HTMLHtmlElement

    Set ie = CreateObject("InternetExplorer.Application")
    ie.navigate "https://portalnacional.com.pt/empresa/florensis-portugal-producao-floricola-sociedade-unipessoal-lda-289251/"
    Set HTML = ie.Document
    
    
For Each elc In HTML.getElementsByClassName("value")
   Debug.Print elc.innerText
Next

Any thoughts ?
 

Isaac

Lifelong Learner
Local time
Yesterday, 18:14
Joined
Mar 14, 2017
Messages
2,734
Add in some code to wait a few seconds to make sure the web page is loaded. Look for examples containing Readystate
 

cpampas

Registered User.
Local time
Yesterday, 18:14
Joined
Jul 23, 2012
Messages
69
Pisorsisaac,
It is not the lack of a waiting time, as I have runned the code stepping through code

MickJav,
I have read the link you sent, but I cant figure out how it can help me.
I noticed that HTML of the elements I can succesefully get data from is:

Code:
<div class="value">Florensis Portugal - Produção Florícola, Sociedade Unipessoal Lda.</div>

but the one I am having problems with is :

Code:
<div class="value"><img src="/images/text.php?type=empresa&amp;field=telefone&amp;id_empresa=289251"></div>
 

Isaac

Lifelong Learner
Local time
Yesterday, 18:14
Joined
Mar 14, 2017
Messages
2,734
I don't see how stepping through the code would solve the problem that I implied. Adding a do while loop 4 ready state is a pretty typical approach
 

cheekybuddha

AWF VIP
Local time
Today, 02:14
Joined
Jul 21, 2014
Messages
557
What do you expect to get?

<div class="value"><img src="/images/text.php?type=empresa&amp;field=telefone&amp;id_empresa=289251"></div> does not have any innerText.
 

cpampas

Registered User.
Local time
Yesterday, 18:14
Joined
Jul 23, 2012
Messages
69
I would expect to get the value visible when we load the webpage wich is 265898211
Can I not retrieve that value because it's not text , but an Image ? anyway to do it ?
thanks
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:14
Joined
Oct 29, 2018
Messages
13,202
I would expect to get the value visible when we load the webpage wich is 265898211
Can I not retrieve that value because it's not text , but an Image ? anyway to do it ?
thanks
I think that's the web developer's approach with preventing web page scrapers from harvesting personal data (e.g. telephone). The "safest" approach is to ask the web owner for a web service you can submit query requests to.
 

cheekybuddha

AWF VIP
Local time
Today, 02:14
Joined
Jul 21, 2014
Messages
557
Yes, I agree with DBG - it's designed specifically to prevent you doing what you are trying to do.
 

cpampas

Registered User.
Local time
Yesterday, 18:14
Joined
Jul 23, 2012
Messages
69
by the way, another possibility, would be to download the image and store it in my database, so instead of having the field PhoneNumber as a string it would be an image, plus the phone number is not relevant as a search string
do you believe this would be a solution ? taking into account that my database would have hundreds of thousands of records ?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:14
Joined
Oct 29, 2018
Messages
13,202
by the way, another possibility, would be to download the image and store it in my database, so instead of having the field PhoneNumber as a string it would be an image, plus the phone number is not relevant as a search string
do you believe this would be a solution ? taking into account that my database would have hundreds of thousands of records ?
Hmm, the image seems small enough, but what's wrong with going with the web service approach, provided it's available?
 

cpampas

Registered User.
Local time
Yesterday, 18:14
Joined
Jul 23, 2012
Messages
69
Definetly your suggestion would be my first choice if posible. I ll check into that
Thanks a lot for your help
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:14
Joined
Oct 29, 2018
Messages
13,202
Definetly your suggestion would be my first choice if posible. I ll check into that
Thanks a lot for your help
I think that would be best, if available. With web scraping, you would be at the mercy of the web designer. A simple web page design change could break your code. Good luck!
 

Users who are viewing this thread

Top Bottom