9 Replies - 2802 Views - Last Post: 16 October 2012 - 06:46 AM Rate Topic: -----

#1 aff219@gmail.com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-October 12

why does my list have "about:" in the results?

Posted 10 October 2012 - 11:13 PM

html code:
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html>
<head>
	<title>Testing</title>
</head>
<body>
<div id="content">
	<p>demo</p>
	<area alt="Open for 1" href="region.php?reg=1">
	<area alt="Closed href="region.php?reg=2">
	<area alt="Closed" href="region.php?reg=3"">
	<area alt="Closed" href="region.php?reg=4">
	<area alt="open for 2" href="region.php?reg=5">
	<area alt="closed" href="region.php?reg=6">
	<area alt="closed" href="region.php?reg=7">
	<area alt="closed" href="region.php?reg=8">
	<area alt="open for 3" href="region.php?reg=9">
	<area alt="open for 4" href="region.php?reg=10">
	<area alt="closed" href="region.php?reg=11">
	<area alt="open for 5" href="region.php?reg=12">
</div>	
</body>
</html>



applications code:
    Private FindThese As String() = {"open for 3", "open for 1"}


        Dim Items = _
         ( _
             From T In WebBrowser1.document.GetElementsByTagName("area").Cast(Of HtmlElement)() _
             Where T.GetAttribute("href").ToString.ToLower.Contains("region.php?reg=") AndAlso _
             FindThese.Contains(T.GetAttribute("alt").ToString.ToLower) _
             Select Link = T.GetAttribute("href"), Alt = T.GetAttribute("alt") _
         ).ToList

        ListBox1.DisplayMember = "link"
        ListBox1.DataSource = Items



I'm using a listbox as a debugging tool to see what data gets pulled for use. The end result will be using the list to navigate webbrowser1.

The goal is to read the HTML, locate the <area> tags with the desired values, snag the links associated with them, and navigate webbrowser1 to the corresponding page.

Everythings going well except for ONE issue: the resulting data pulled is:
Posted Image

one way or another, i need to figure out how to remove the "about:" portion so i can use it to navigate webbrowser1 to "www.***.com/region.php?reg=X"

currently the result is webbrowser1 attempts to go to "www.***.com/about:region.php?reg=x", which obviously is not going to work.

lots of googling and tinkering has yielded absolutely no answers as to why im getting this

Is This A Good Question/Topic? 0
  • +

Replies To: why does my list have "about:" in the results?

#2 PeterH  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 47
  • Joined: 03-September 09

Re: why does my list have "about:" in the results?

Posted 11 October 2012 - 02:54 AM

You know far more about this than me but cant you simply check and if present remove the 'about:' portion from the string value before adding it to the list something like e.g

 If a.Contains("about:") Then
            a.Remove(0, 5)
end if


Was This Post Helpful? 0
  • +
  • -

#3 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 57
  • View blog
  • Posts: 292
  • Joined: 22-August 11

Re: why does my list have "about:" in the results?

Posted 11 October 2012 - 05:23 AM

post the rest of the code of the Private Items section.
Was This Post Helpful? 0
  • +
  • -

#4 manos364  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 42
  • Joined: 09-October 12

Re: why does my list have "about:" in the results?

Posted 11 October 2012 - 06:11 AM

Use the Replace command in order to remove "about:". That's need the removal of all items and their reenter.

    Public Shared Sub UpdateListBoxItemText(ByVal ListBox As ListBox)
        ' Create a new ArrayList used to reverse items.
        Dim List As New ArrayList
        ' Add all items from the ListBox to the ArrayList.
        List.AddRange(ListBox.Items)
        ' Remove all items from ListBox.
        ListBox.Items.Clear()
        For Index As Integer = 0 To List.Count - 1
            ' Add items again replacing the "about:" with nothing.
            ListBox.Items.Add(List.Item(Index).ToString.Replace("about:", ""))
        Next
        ' Clear List for later use.
        List.Clear()
        ' *** BEWARE *** *** IF TEXT AFTER "about:" CONTAINS "about:" AGAIN, IT WILL BE REMOVED! ***
    End Sub

    Public Shared Sub ChangeListBoxItemText(ByVal ListBox As ListBox, ByVal ItemIndex As Integer, ByVal ReplaceOldText As String, ByVal ReplaceNewText As String)
        ' Create new String to save item to remove value.
        Dim TempStr As String = ListBox.Items.Item(ItemIndex)
        ' Remove item.
        ListBox.Items.RemoveAt(ItemIndex)
        ' Enter new item again to it's original position
        ListBox.Items.Insert(ItemIndex, TempStr.Replace(ReplaceOldText, ReplaceNewText))
        ' *** BEWARE *** *** IF TEXT AFTER "about:" CONTAINS "about:" AGAIN, IT WILL BE REMOVED! ***
    End Sub



Use one of these based on if you want to replace "about:" of all items or from just one specific item.
Was This Post Helpful? 0
  • +
  • -

#5 Bort  Icon User is offline

  • Ill-informed Mongoloid
  • member icon

Reputation: 414
  • View blog
  • Posts: 3,024
  • Joined: 18-September 06

Re: why does my list have "about:" in the results?

Posted 11 October 2012 - 06:33 AM

First thing I spotted was that there are some speechmarks either missing, or in the wrong place.

In your HTML code, on line 10, there should be " after the word Closed, and on line 11, you have "" at the end of the line. I'm pretty sure this should just be ".

Also, on line 12 of the application code, try removing the speechmarks around the word link, and adding .ToString on the end of it instead:

ListBox1.DisplayMember = link.ToString


Was This Post Helpful? 0
  • +
  • -

#6 aff219@gmail.com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-October 12

Re: why does my list have "about:" in the results?

Posted 11 October 2012 - 01:56 PM

View Postmanos364, on 11 October 2012 - 06:11 AM, said:

Use the Replace command in order to remove "about:". That's need the removal of all items and their reenter.

    Public Shared Sub UpdateListBoxItemText(ByVal ListBox As ListBox)
        ' Create a new ArrayList used to reverse items.
        Dim List As New ArrayList
        ' Add all items from the ListBox to the ArrayList.
        List.AddRange(ListBox.Items)
        ' Remove all items from ListBox.
        ListBox.Items.Clear()
        For Index As Integer = 0 To List.Count - 1
            ' Add items again replacing the "about:" with nothing.
            ListBox.Items.Add(List.Item(Index).ToString.Replace("about:", ""))
        Next
        ' Clear List for later use.
        List.Clear()
        ' *** BEWARE *** *** IF TEXT AFTER "about:" CONTAINS "about:" AGAIN, IT WILL BE REMOVED! ***
    End Sub

    Public Shared Sub ChangeListBoxItemText(ByVal ListBox As ListBox, ByVal ItemIndex As Integer, ByVal ReplaceOldText As String, ByVal ReplaceNewText As String)
        ' Create new String to save item to remove value.
        Dim TempStr As String = ListBox.Items.Item(ItemIndex)
        ' Remove item.
        ListBox.Items.RemoveAt(ItemIndex)
        ' Enter new item again to it's original position
        ListBox.Items.Insert(ItemIndex, TempStr.Replace(ReplaceOldText, ReplaceNewText))
        ' *** BEWARE *** *** IF TEXT AFTER "about:" CONTAINS "about:" AGAIN, IT WILL BE REMOVED! ***
    End Sub



Use one of these based on if you want to replace "about:" of all items or from just one specific item.


I'm afraid those ideas arent going to suit what i need, the end result will have no listbox, so I need to work with the list directly if at all possible

View PostPeterH, on 11 October 2012 - 02:54 AM, said:

You know far more about this than me but cant you simply check and if present remove the 'about:' portion from the string value before adding it to the list something like e.g

 If a.Contains("about:") Then
            a.Remove(0, 5)
end if


i will admit that i am very new to programming and may be missing fundamental steps, but I don't think that code works vs a list, if im incorrect please enlighten me


View Posttorind_2000, on 11 October 2012 - 05:23 AM, said:

post the rest of the code of the Private Items section.


the only bit of code for this section of my programming not posted is the end sub statement. That's everything as of the moment.

View PostBort, on 11 October 2012 - 06:33 AM, said:

First thing I spotted was that there are some speechmarks either missing, or in the wrong place.

In your HTML code, on line 10, there should be " after the word Closed, and on line 11, you have "" at the end of the line. I'm pretty sure this should just be ".

Also, on line 12 of the application code, try removing the speechmarks around the word link, and adding .ToString on the end of it instead:

ListBox1.DisplayMember = link.ToString



I tried your suggestions
I cleaned up the temp HTML code, then did the link.tostring part, but it doesnt want to allow it, invalid option there.
Was This Post Helpful? 0
  • +
  • -

#7 aff219@gmail.com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-October 12

Re: why does my list have "about:" in the results?

Posted 11 October 2012 - 09:27 PM

Okay, i've now attempted many different things and nothing works.

I have converted the list to a string, then use replace commands to attempt to remove the "about:" portion to no avail.

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Items = _
         ( _
             From T In WebBrowser1.document.GetElementsByTagName("area").Cast(Of HtmlElement)() _
             Where T.GetAttribute("href").ToString.ToLower.Contains("region.php?reg=") AndAlso _
             FindThese.Contains(T.GetAttribute("alt").ToString.ToLower) _
             Select Link = T.GetAttribute("href"), Alt = T.GetAttribute("alt") _
         ).ToList

        Dim itemstring As String = String.Join(",", Items)

        Dim value1 As String = itemstring.Replace("about:", "")


        RichTextBox3.Text = value1
        ListBox1.DisplayMember = "link"
        ListBox1.DataSource = Items



This yeilds no errors, but accomplishes no results, it doesnt see the "about:" portion. Changing the repalcement value to "region.php?=reg" however will work. This tells me the about: part isnt actually being considered part of the link, even though using browser1.navigate with link still produces the about: in the result

its something vb is throwing it, though I dont know why, or how to get rid of it.
Was This Post Helpful? 0
  • +
  • -

#8 PeterH  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 47
  • Joined: 03-September 09

Re: why does my list have "about:" in the results?

Posted 12 October 2012 - 05:34 AM

Don't want to waste your time here, but after searching around I found somthing here;

http://browsers.abou...tartup_page.htm

which talks about the browser.startup.page settings i.e. 0 = 'about:', could it be that it is this value being returned in your link field.
Was This Post Helpful? 0
  • +
  • -

#9 aff219@gmail.com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-October 12

Re: why does my list have "about:" in the results?

Posted 15 October 2012 - 11:25 PM

View PostPeterH, on 12 October 2012 - 05:34 AM, said:

Don't want to waste your time here, but after searching around I found somthing here;

http://browsers.abou...tartup_page.htm

which talks about the browser.startup.page settings i.e. 0 = 'about:', could it be that it is this value being returned in your link field.



i dont think thats the solution becuase if im not mistaken, by default vb.net uses ie, not ff, and secondly thats when opening a new tab/page without navigating to a url, where this is generating the about: WITH the url along with it
Was This Post Helpful? 0
  • +
  • -

#10 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: why does my list have "about:" in the results?

Posted 16 October 2012 - 06:46 AM

Dim Items = _
         ( _
             From T In WebBrowser1.document.GetElementsByTagName("area").Cast(Of HtmlElement)() _
             Where T.GetAttribute("href").ToString.ToLower.Contains("region.php?reg=") AndAlso _
             FindThese.Contains(T.GetAttribute("alt").ToString.ToLower) _
             Select Link = T.GetAttribute("href").ToString.Remove(0,6), Alt = T.GetAttribute("alt") _
         ).ToList


The about: is happening in the GetAttribute (probably because it's not a valid href but that's just a guess) Anyway, for your purpose, using your original code you submitted, the above code removes the about: from that result.

This post has been edited by CharlieMay: 16 October 2012 - 06:54 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1