2
Contributors
12
Replies
13
Views
5 Years
Discussion Span
Last Post by thines01
0

Does it really need to "click" the link or just navigate to the address?

when a user goes onto a page and clicks a link that is the effect i want to acheive
so all the correct refereals etc.. get given

0

...but what you're after is the effect of what's on the next page, right?
You can simulate tjat by just opening the next page.
If the second page really needs a referral (from the previous page), you can do that with the HttpWebRequest/Response construction.

It really depends on what you're after, though.

0

...but what you're after is the effect of what's on the next page, right?
You can simulate tjat by just opening the next page.
If the second page really needs a referral (from the previous page), you can do that with the HttpWebRequest/Response construction.

It really depends on what you're after, though.

ok so webbrowser loads page www.blahblah.com

on page there is link http://sdlfhsd;fjhsdfjhs;jfhs;kjdfhsdlfhsdkjfhsdfj

i want a way for the code to sarch page for link each link has a common name

and just click it as though you or me clicked it


thanks for your time buddy

0

I understand that part.
What is going to happen when it is "clicked"?

Do you:
1) just want to SEE the next page in a browser
or
2) want SOMETHING from that next page?

0

the next page will just show in same page

so i want the code to click link and it will show in same page _self

and thats all ;)

thanks again

0

In this example, the user will need to enter a partial URL.
If found in the WebBrowser control, it will navigate to that link.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace DW_417357_CS_FORM
{
   public partial class Form1 : Form
   {
      public Form1()
      {
         InitializeComponent();
      }

      private void Form1_Load(object sender, EventArgs e)
      {
         List<string> lst_strLinks = new List<string>
         {
            "one <a href='http://www.textpad.com'>TextPad</a>",
            "two <a href='http://www.DaniWeb.com'>DaniWeb</a>",
            "three <a href='http://www.Bing.com'>Bing</a>",
         };

         StringBuilder sbLinks = new StringBuilder(lst_strLinks.Count);
         lst_strLinks.ForEach(s => sbLinks.Append(s+"<br />"));
         webBrowser1.DocumentText = sbLinks.ToString();
      }

      private void bnNavigate_Click(object sender, EventArgs e)
      {
         if (string.IsNullOrEmpty(txtUrlFragment.Text))
         {
            MessageBox.Show("Please enter a partial URL");
            return;
         }

         // A very simplistic regex for capturing links
         Regex rxLinks = new Regex(@"'(?<url>http://.*)'");

         string strLink = // could be null or empty
            // split the contents of the text/html in the web browser
            webBrowser1.DocumentText.Split("<>\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
            // check to see if they are links
            .Where(s => rxLinks.IsMatch(s)).Select(s => rxLinks.Match(s).Groups["url"].Value)
            // check to see if they match what the user entered and get the first one.
            .Where(s => s.ToLower().Contains(txtUrlFragment.Text.ToLower())).FirstOrDefault();

         if (string.IsNullOrEmpty(strLink))
         {
            MessageBox.Show("Not found");
            return;
         }

         webBrowser1.Navigate(strLink);
      }
   }
}
Attachments DW_417357-1.jpg 22.55 KB DW_417357-2.jpg 46.54 KB
0

hi there , let me say first thank you very much for your amazing effort

i tried to compile this code and i have 2 errors

Error 1 The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) c:\users\randy\documents\visual studio 2010\Projects\WindowsFormsApplication5\WindowsFormsApplication5\Form1.cs 3 14 WindowsFormsApplication5
Error 2 'System.Array' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) c:\users\randy\documents\visual studio 2010\Projects\WindowsFormsApplication5\WindowsFormsApplication5\Form1.cs 46 17 WindowsFormsApplication5


cheers

0

You should be compiling for .NET 3.5 or higher and you might need to add System.Core to the references section in the project.

0

You should be compiling for .NET 3.5 or higher and you might need to add System.Core to the references section in the project.

hi there but i am useing .net 2.0

and that is what i need
for easier compatibility for users

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.