Simple programming-character statistics
Click this link →http://ctf.idf.cn/game/pro/37
You will see the topic, to quickly submit the answer Oh, the content will change after the refresh, so make a program to read the page, and then calculate.
-------------------------------------------------------------------------------------------------
Analysis:
Find someone on the net to solve the good, I will not say much.
Solution on the Web 1: "Java program implementation"
At first thought as long as simple statistics good, then a look, found unexpectedly written to be submitted within 2 seconds ... Well, didn't notice, so decided to use HttpWebRequest to complete. Grab the bag with HttpWatch, come out a post the data submitted is answer=. , blame my poor foundation, no matter how to change the code, the data are not post up ah ... Depressed.
Think of a previous software, with the WebBrowser, try it, the code is as follows:
<pre name= "code" class= "Java" >using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Text;
Using System.Windows.Forms;
Using System.Web;
Using System.Net;
Using System.IO;
Namespace simple character Statistics {public partial class Form1:form {public Form1 () {InitializeComponent ();
The public string Getword (string str) {int w = 0, o = 0, l = 0, d = 0, y = 0; char[] ch = str.
ToCharArray (); for (int i = 0; i < str. Length;
i++) {if (ch[i] = = ' W ') w++;
if (ch[i] = = ' o ') o++;
if (ch[i] = = ' l ') l++;
if (ch[i] = = ' d ') d++;
if (ch[i] = = ' y ') y++;
} Return W + "" + O + "" + L + "" + D + "" + y; The private void button2_click (object sender, EventArgs e) {webbrowser1.navigate ("http://ctf.idf.cn/game/pr
O/37/index.php ");
} public int flag = 1; private void Webbrowser1_documentcomplEted (object sender, WebBrowserDocumentCompletedEventArgs e) {StreamReader getreader = new StreamReader (This.webb Rowser1.
Documentstream, System.Text.Encoding.GetEncoding ("gb2312"));
String gethtml = Getreader.readtoend (); int a = gethtml.
IndexOf ("
Success, moved to the author tears.
Submitted, passed.
-------------------------------------------------------------------------
Solution 2, Calculate with Python program
Refer to the solution of http://blog.csdn.net/u012241633/article/details/45766281, small change one.
This program not only to catch Web content, post method to submit request, get response, but also pay special attention to the use of cookies, the server with a cookie to distinguish users, so submit to verify the cookie, do not match the task is not you do.
#-*-coding:utf-8-*-import urllib import urllib2 Import string import re import cookielib #需要提交post的url
Target_url = "http://ctf.idf.cn/game/pro/37/" "Do not take cookies, WP = URLLIB.URLOPEN (target_url) content = Wp.read ()" # Set a cookie processor req = urllib2. Request (target_url) CJ = Cookielib. Cookiejar () opener = Urllib2.build_opener (urllib2. Httpcookieprocessor (CJ) res = Opener.open (req) content = res.read () ct = Re.findall (R '