|
-
Jul 29th, 2006, 08:14 PM
#1
Thread Starter
New Member
Scraping Links from Web??? help please?
I am using webbrowser control to login to a webpage and auto submit login, email and password with this code:
VB Code:
Webbrowser1.Document.All("usrname").Focus()
Webbrowser1.Document.ActiveElement.InnerText = txt_user.Text
Webbrowser1.Document.All("uemail").Focus()
Webbrowser1.Document.ActiveElement.InnerText = txt_email.Text
Webbrowser1.Document.All("peeword").Focus()
Webbrowser1.Document.ActiveElement.InnerText = txt_pass.Text
Webbrowser1.Document.Forms(0).InvokeMember("Submit")
Yes, I'm a noob but it works so after a long time finding out vb.net 2005 didn't support formname.submit() I was very happy to get this working
Anyhow, I am now trying to use webbrowser control to scrape links with stats.php?id=6digit#here in it's link. I've tried everything I can possibly think of over the past few days and am lost. ANY help will be much appreciated. Thanks
Kevin
Last edited by khuntballa; Jul 29th, 2006 at 08:44 PM.
-
Jul 30th, 2006, 12:25 AM
#2
Thread Starter
New Member
Re: Scraping Links from Web??? help please?
^ Sorry to bump but I really am completely lost here if I could get any help I'd love it. Thanks
-
Jul 30th, 2006, 02:33 AM
#3
Re: Scraping Links from Web??? help please?
Here is an example that should get you started:
VB Code:
Dim scrapedLinks As New List(Of HtmlAnchorElement)
Dim allLinks As HtmlElementCollection = Webbrowser1.GetElementsByTagName("a")
For Each link as HtmlAnchorElement In allLinks
If (link.GetAttribute("href").IndexOf("stats.php?id=6digit#here") > 0) Then
scrapedLinks.Add(link)
End If
Next
Untested, hope the class names are right.
-
Jul 30th, 2006, 11:39 AM
#4
Thread Starter
New Member
Re: Scraping Links from Web??? help please?
Thanks for replying, I tried
VB Code:
Webbrowser1.Navigate("http://www.kingsofchaos.com/battlefield.php?" & "start=" & txt_low.Text)
Dim scrapedLinks As New List(Of HTMLAnchorElement)
Dim allLinks As HTMLElementCollection = Webbrowser1.Document.GetElementsByTagName("a")
For Each link As HTMLAnchorElement In allLinks
If (link.getAttribute("href").IndexOf("stats.php?id=") > 0) Then
scrapedLinks.Add(link)
End If
Next
without adding an
VB Code:
Imports System.Collections.Generic
I got an error list not defined.
Now the error I am getting is unable to cast object of type system.windows.forms.htmlcollection to type mshtml.htmlelementcollection. I have added the imports statement for mshtml.... any help is apreciated
-
Jul 30th, 2006, 11:40 AM
#5
Re: Scraping Links from Web??? help please?
Oh... change HTMLElementCollection to HTMLCollection then.
-
Jul 30th, 2006, 11:43 AM
#6
Thread Starter
New Member
Re: Scraping Links from Web??? help please?
htmlcollection is not defined

Again thanks for helping me penagate
Last edited by khuntballa; Jul 30th, 2006 at 11:48 AM.
-
Jul 30th, 2006, 12:04 PM
#7
Re: Scraping Links from Web??? help please?
I was right its HtmlElementCollection.
VB Code:
Dim allLinks As HtmlElementCollection = Webbrowser1.Document.GetElementsByTagName("a")
that should work 
http://msdn2.microsoft.com/en-us/lib...bytagname.aspx
-
Jul 30th, 2006, 12:10 PM
#8
Thread Starter
New Member
Re: Scraping Links from Web??? help please?
It is still getting
unable to cast object of type system.windows.forms.htmlcollection to type mshtml.htmlelementcollection
Any ideas what could be causing that?
Last edited by khuntballa; Jul 30th, 2006 at 12:15 PM.
-
Jul 30th, 2006, 12:17 PM
#9
Re: Scraping Links from Web??? help please?
Well then the documentation is incorrect because that's what they've used 
I'll give it a try
-
Jul 30th, 2006, 12:28 PM
#10
Re: Scraping Links from Web??? help please?
It worked for me although I needed to change HtmlAnchorElement to HtmlElement.
-
Jul 30th, 2006, 12:33 PM
#11
Thread Starter
New Member
Re: Scraping Links from Web??? help please?
Hrmm,
I am using 2005 could that be a reason?
-
Jul 30th, 2006, 12:37 PM
#12
Re: Scraping Links from Web??? help please?
So am I and so is the documentation which explicitly says it is a new method in the Framework 2.0
-
Jul 30th, 2006, 01:24 PM
#13
Thread Starter
New Member
Re: Scraping Links from Web??? help please?
This is what I am trying w/ a completely new application now
VB Code:
WebBrowser2.Navigate("www.kingsofchaos.com/battlefield.php")
Dim scrapedLinks As New List(Of HtmlElement)
Dim allLinks As HTMLElementCollection = webBrowser2.Document.GetElementsByTagName("a")
For Each link As HtmlElement In allLinks
If (link.GetAttribute("href").IndexOf("stats.php?id=") > 0) Then
scrapedLinks.Add(link)
End If
Next
And the Error I am getting is Unable to cast object of type system.Windows.forms.htmlelementcollection to type mshtml.htmlelementcollection
Did you add any additional references? I added mshtml and that was it
A first chance exception of type 'System.NullReferenceException' occurred in DarkFuryToolz.exe
A first chance exception of type 'System.NullReferenceException' occurred in DarkFuryToolz.exe
In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.
I get this for:
Dim allLinks As HTMLElementCollection = webBrowser2.Document.GetElementsByTagName("a")
Last edited by khuntballa; Jul 30th, 2006 at 08:58 PM.
-
Jul 30th, 2006, 06:21 PM
#14
Thread Starter
New Member
Re: Scraping Links from Web??? help please?
-
Jul 30th, 2006, 09:24 PM
#15
Re: Scraping Links from Web??? help please?
 Originally Posted by khuntballa
I added mshtml and that was it
Daah, that's the problem. Take it out 
It's an ambigous reference.
-
Jul 30th, 2006, 10:04 PM
#16
Thread Starter
New Member
Re: Scraping Links from Web??? help please?
Still getting
Object reference not set to an instance of an object.
and it is highlighting
VB Code:
Dim allLinks As HTMLElementCollection = webBrowser2.Document.GetElementsByTagName("a")
-
Jul 30th, 2006, 10:28 PM
#17
Hyperactive Member
Re: Scraping Links from Web??? help please?
You probably don't have a document loaded in webBrowser2. Try adding a check that webBrowser2 has a document.
-
Jul 31st, 2006, 01:14 AM
#18
Thread Starter
New Member
Re: Scraping Links from Web??? help please?
I'll probably sound stupid for asking this, but how do I actually view that list to check it's exact output?
I tried doing listbox2.items.add(link) in the loop and it came up as htmlelement 50 times
-
Jul 31st, 2006, 01:20 AM
#19
Hyperactive Member
Re: Scraping Links from Web??? help please?
I don't know for sure, but I'd guess a member of link would have what you want... probably value or text or something similar
-
Jul 31st, 2006, 07:51 AM
#20
Re: Scraping Links from Web??? help please?
It needs to be done in the DocumentComplete event
-
Aug 2nd, 2006, 03:18 AM
#21
Thread Starter
New Member
Re: Scraping Links from Web??? help please?
So the last thing before I close this thread, is how do I export that list to something readable by me in thne correct format? like when I tried adding it to a listbox all I got was htmlelement instead of the link
-
Aug 2nd, 2006, 04:36 AM
#22
Re: Scraping Links from Web??? help please?
Make sure you have "Option Strict On" at the top of your code file. This should prevent you from doing things which don't make sense, like listbox2.items.add(link).
Next, type a dot "." after "link" and you'll see everything you need.
-
Mar 3rd, 2007, 10:21 AM
#23
Junior Member
Re: Scraping Links from Web??? help please?
can u make it in normal VB 6.0??
-
Mar 3rd, 2007, 10:24 AM
#24
Re: Scraping Links from Web??? help please?
-
Mar 3rd, 2007, 03:06 PM
#25
Re: Scraping Links from Web??? help please?
 Originally Posted by penagate
Nice recommendation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|