Captures HTTP and email addresses, Io, and regular expressions in the webpage code in batches, and captures the webpage source code.

Source: Internet
Author: User

The meeting last week said that Chinese Spam is making money now. I also want to make more money. However, all technologies are rigid. The brain shell is not flexible. You can only study some methods to implement program code like this and collect and organize the code for two days. Finally, find the desired code. It's not perfect. It can be improved a lot.
Using system. IO;
Using system. Text. regularexpressions;

Public String getpagecontent (string URL)
{

// Capture the webpage source code
String contenthtml = string. empty;
Httpwebrequest RT = NULL;
Httpwebresponse rs = NULL;
Stream stream = NULL;
Streamreader sr = NULL;
 
RT = (httpwebrequest) webrequest. Create (URL );
Rs = (httpwebresponse) rt. getresponse ();
Stream = Rs. getresponsestream ();
Sr = new streamreader (stream, system. Text. encoding. Default );
Contenthtml = Sr. readtoend ();
Sr. Close ();
Stream. Close ();
Rs. Close ();
Return contenthtml;

}

Public String sethttpurl (string strtext)
{
// Use regular expressions to identify URL hyperlinks
RegEx urlregex = new RegEx (@ "(http: // ([/W.] + //?) /S *) ", regexoptions. ignorecase | regexoptions. Compiled );
// Enter the URL of the Rule Query
Matchcollection matches = urlregex. Matches (strtext );
Foreach (match in matches)
{
Strtext = strtext. replace (match. value, String. format ("<a href =/" {0}/"target =/" _ blank/"> {1} </a>", match. value, match. value ));
}
Return strtext;
}

Public String setemailurl (string strtext)
{
// Use regular expressions to recognize the email address
RegEx emailregex = new RegEx (@ "([a-zA-Z_0-9.-] +/@ [a-zA-Z_0-9.-] +/./W +)", regexoptions. ignorecase | regexoptions. Compiled );
Matchcollection matches = emailregex. Matches (strtext );

Foreach (match in matches)
{
Strtext = strtext. replace (match. value, String. format ("<a href = mailto: {0 }>{ 1} </a>", match. value, match. value ));
}
Return strtext;
}

Public String gethttpurl (string strtext)
{

// Write all the read URLs into text files.
String strpageurlfilename = application. startuppath + "// httppageurl.txt ";
Streamwriter strwriterobj = file. createtext (strpageurlfilename );

// Use regular expressions to recognize URL hyperlinks and enter the URL for rule Query
RegEx urlregex = new RegEx (@ "(http: // ([/W.] + //?) /S *) ", regexoptions. ignorecase | regexoptions. Compiled );
Matchcollection matches = urlregex. Matches (strtext );
Foreach (match in matches)
{
Lsthttp. Items. Add (match. value. tostring ());
Strwriterobj. writeline (match. value. tostring ());
}
Strwriterobj. Close ();
Return strtext;

}

Public String getemailurl (string strtext)
{
// Write all the read URLs into text files.
String strpageemailfilename = application. startuppath + "// httppageemail.txt ";
Streamwriter strwriterobj = file. createtext (strpageemailfilename );

// Use regular expressions to recognize the email address
RegEx emailregex = new RegEx (@ "([a-zA-Z_0-9.-] +/@ [a-zA-Z_0-9.-] +/./W +)", regexoptions. ignorecase | regexoptions. Compiled );
Matchcollection matches = emailregex. Matches (strtext );
Foreach (match in matches)
{
Lstemail. Items. Add (match. value. tostring ());
Strwriterobj. writeline (match. value. tostring ());
}
Strwriterobj. Close ();
Return strtext;

}

Captures HTTP and email addresses, Io, and regular expressions in the webpage code in batches, and captures the webpage source code.

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.