Publish source code, new programs, analyze Web pages, take specified values, store, manipulate web pages, fill in values, simulate clicks, fault tolerance, and send.

Source: Internet
Author: User

Publish source code, new programs, analyze Web pages, take specified values, store, manipulate web pages, fill in values, simulate clicks, fault tolerance, and send.

To add more people in the circle of friends, I wrote this program, extracted the usernames in the member list, wrote them to dataview, and filled them in the textbox. The program automatically clicked "invite ". Webbrowser is used to analyze HTML and operate some controls on the webpage, such as clicking and buttons. Enter the content.

There are not many codes, so I can understand it at a glance and won't write more.

 

The source code is as follows:

 

Using System;
Using System. IO;
Using System. Net;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;

Namespace WindowsApplication2
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
// Obtain the html source code of the webpage based on the Url
Private string GetWebContent (string Url)
{
String strResult = "";
Try
{
HttpWebRequest request = (HttpWebRequest) WebRequest. Create (Url );
// Declare an HttpWebRequest request
Request. Timeout = 30000;
// Set the connection timeout
/*
Http://blog.csdn.net/metababy
Http://hexun.com/metababy
Http://ike.126.com flower spring
*/
Request. Headers. Set ("Pragma", "no-cache ");
HttpWebResponse response = (HttpWebResponse) request. GetResponse ();
Stream streamReceive = response. GetResponseStream ();
Encoding encoding = Encoding. GetEncoding ("GB2312 ");
StreamReader streamReader = new StreamReader (streamReceive, encoding );
StrResult = streamReader. ReadToEnd ();
}
Catch
{
MessageBox. Show ("error ");
}
Return strResult;
}

Private void button#click (object sender, EventArgs e)
{
WebBrowser1.Navigate ("http://group.hexun.com/qiniuzhe/invite.aspx ");
// The URL to be crawled
String Url = textBox1.Text;

// Obtain the source code of the specified Url
String strWebContent = GetWebContent (Url );


// Retrieve the Source Code related to the data
Int iBodyStart = strWebContent. IndexOf ("<body", 0 );
Int iStart1 = strWebContent. IndexOf ("next page", iBodyStart );
// Int iTableStart1 = strWebContent. IndexOf ("<table", iStart1 );
Int iTableStart = strWebContent. IndexOf ("<table", iStart1 );
// Int iTableEnd1 = strWebContent. IndexOf ("</table>", iTableStart );
Int iTableEnd = strWebContent. IndexOf ("</table>", iTableStart );
String strWeb = strWebContent. Substring (iTableStart, iTableEnd-iTableStart + 8 );




// Generate HtmlDocument
WebBrowser webb = new WebBrowser ();
Webb. Navigate ("about: blank ");
HtmlDocument htmldoc = webb. Document. OpenNew (true );

Htmldoc. Write (strWeb );






HtmlElementCollection htmlTD = htmldoc. GetElementsByTagName ("TD ");
Foreach (HtmlElement td in htmlTD)
{
String strID = td. InnerText;
Int IDend = strID. Length;
Intidstart = strID. LastIndexOf ("200 ");
Int ij = IDstart-1;
String abc = strID. Substring (1, ij );

// String strName = tr. GetElementsByTagName ("TD") [1]. InnerText;
// String strSinger = tr. GetElementsByTagName ("TD") [1]. InnerText;
// StrID = strID. Replace (".","");
// Insert a DataTable
/*
Http://blog.csdn.net/metababy
Http://hexun.com/metababy
Http://ike.126.com flower spring
*/

Maid = this. Maid;
Drow. Add (abc );







}

}
Int iii =-1;

Private void button2_Click (object sender, EventArgs e)
{
WebBrowser1.Navigate ("http://group.hexun.com/qiniuzhe/invite.aspx ");

Iii = iii + 1;
WebBrowser1.DocumentCompleted + = new WebBrowserDocumentCompletedEventHandler (test );

}

Private void test (object sender, WebBrowserDocumentCompletedEventArgs e)
{

HtmlElementCollection webUser = webBrowser1.Document. All. GetElementsByName ("User ");

If (iii <Convert. ToInt32 (dataGridView1.Rows. Count. ToString ()))
{

This. Maid = this. Maid [0, iii];


WebUser [0]. InnerText = maid ();

HtmlElementCollection webSub = webBrowser1.Document. All. GetElementsByName ("submitInvite ");
WebSub [0]. InvokeMember ("click ");

}
Else
{
MessageBox. Show ("finished! ");
}
/*
Http://blog.csdn.net/metababy
Http://hexun.com/metababy
Http://ike.126.com
*/

}

}
}

Download source code: http://files.cnblogs.com/meta/WindowsApplication2.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.