0

I am trying to develop an automated bot in VS 2015 using C#. I have web browser control, 1 listbox, 1 textbox, 1 button. Now on button click, I want to ask is it possible to automatically iterate through the listbox items one by one (I mean select 1 item from listbox then send that string to google then select next item from listbox do the same and so on) and sending that string to google search engine in my web browser control and if google show results regarding that query then that string will be stored in multiline textbox ?

Can someone suggest me how is it possible ? Below is my code:

public Form1()
{
    InitializeComponent();            
    webBrowser1.Navigate("http://www.bing.com/?scope=web&mkt=en-US");            
}        

private void button1_Click(object sender, EventArgs e)
{                   
    for (int i = 0; i < listBox1.Items.Count; i++)
    {                
        listBox1.SelectedIndex = listBox1.SelectedIndex + 1;

        if (listBox1.SelectedIndex <= listBox1.Items.Count - 0)
        {
            HtmlDocument htmlDoc = webBrowser1.Document;                    
            webBrowser1.Document.All["sb_form_q"].InnerText = listBox1.Text;
            webBrowser1.Document.GetElementById("sb_form_go").InvokeMember("click");
        }
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rahul
  • 49
  • 6
  • That is against the terms of service of the pretty much every web search site, I doubt you will find much help doing something the websites don't want you to do. Why not just [use the API](https://developers.google.com/custom-search/json-api/v1/overview) and not try to be shady about it? Also, if you switch to Bing instead of google you get [5000 free searches](https://datamarket.azure.com/dataset/5BA839F1-12CE-4CCE-BF57-A49D98D29A44) per month vs google's free 100/day. See [this answer](http://stackoverflow.com/a/22494400/80274) for other alternitives. – Scott Chamberlain Aug 28 '16 at 14:48
  • thanks scott but i want to use bing, free searches doesn't matter i won't use it much. i just want to know how can i get result from bing web browser using listbox items. – Rahul Aug 28 '16 at 14:50
  • Your question is "without using the API," which is side-stepping the search providers' TOS. You can always write your own using HttpWebRequest and HttpWebResponse classes. Beyond telling you that, I don't feel comfortable helping you with this. – Shannon Holsinger Aug 28 '16 at 15:26
  • ok np but can you tell me how can i use this for loop to iterate items in listbox items one by one because for loop i used above doesn't iterate one by one but stop directly to last item in listbox. – Rahul Aug 29 '16 at 04:09

0 Answers0