1
/**/
/* ************open_login_page.c********** */
2
#include
<
stdio.h
>
3
#include
<
string
.h
>
4
#include
<
curl
/
curl.h
>
5
#include
<
curl
/
types.h
>
6
#include
<
curl
/
easy.h
>
7
8
int
main(
int
argc,
char
*
argv[])
9
{
10
CURL * curl;
11
CURLcode res;
12
13
struct curl_slist * headerlist = NULL;
14
static const char buf[] = " Expect: " ;
15
16
curl_global_init(CURL_GLOBAL_ALL);
17
curl = curl_easy_init();
18
headerlist = curl_slist_append(headerlist, buf);
19
20
if (curl)
21
{
22
curl_easy_setopt(curl, CURLOPT_URL, " https://passport.baidu.com/?login " );
23
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
24
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, " cookie_open.txt " ); // 把服务器发过来的cookie保存到cookie_open.txt
25
26
#ifdef SKIP_PEER_VERIFICATION
27
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L );
28
#endif
29
30
#ifdef SKIP_HOSTNAME_VERFICATION
31
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L );
32
#endif
33
res = curl_easy_perform(curl);
34
35
/**/ /* always cleanup */
36
curl_easy_cleanup(curl);
37
38
/**/ /* free slist */
39
curl_slist_free_all(headerlist);
40
}
41
return 0 ;
42
}
43
44
/**/
/* *******************login_hi_baidu**************** */
45
#include
<
stdio.h
>
46
#include
<
string
.h
>
47
#include
<
curl
/
curl.h
>
48
#include
<
curl
/
types.h
>
49
#include
<
curl
/
easy.h
>
50
51
int
main(
int
argc,
char
*
argv[])
52
{
53
CURL * curl;
54
CURLcode res;
55
56
struct curl_slist * headerlist = NULL;
57
static const char buf[] = " Expect: " ;
58
59
curl_global_init(CURL_GLOBAL_ALL);
60
curl = curl_easy_init();
61
headerlist = curl_slist_append(headerlist, buf);
62
63
if (curl)
64
{
65
curl_easy_setopt(curl, CURLOPT_URL, " https://passport.baidu.com/?login " );
66
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
67
68
curl_easy_setopt(curl,CURLOPT_POSTFIELDS, " username=ea99&password=&psp_tt=0&safeflg=0&return_method=get&u=http://hi.baidu.com/s%5Fyqguo " ); // 设置帐号密码,其余的信息是页面要求的,抓包即可看见。
69
70
curl_easy_setopt(curl,CURLOPT_COOKIEFILE, " cookie_open.txt " ); // 提交第一步保存的cookie
71
curl_easy_setopt(curl,CURLOPT_COOKIEJAR, " cookie_login.txt " ); // 保存登陆后的cookie
72
#ifdef SKIP_PEER_VERIFICATION
73
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L );
74
#endif
75
76
#ifdef SKIP_HOSTNAME_VERFICATION
77
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L );
78
#endif
79
80
res = curl_easy_perform(curl);
81
/**/ /* always cleanup */
82
curl_easy_cleanup(curl);
83
/**/ /* free slist */
84
curl_slist_free_all(headerlist);
85
}
86
return 0 ;
87
}
88
89
90
/**/
/* ***********download_private_page.c***************** */
91
#include
<
stdio.h
>
92
#include
<
string
.h
>
93
#include
<
curl
/
curl.h
>
94
#include
<
curl
/
types.h
>
95
#include
<
curl
/
easy.h
>
96
97
static
size_t write_data(
void
*
ptr, size_t size, size_t nmemb,
void
*
stream)
98
{
99
int written = fwrite(ptr, size, nmemb, (FILE * )stream);
100
return written;
101
}
102
103
int
main(
int
argc,
char
*
argv[])
104
{
105
CURL * curl;
106
CURLcode res;
107
108
static const char * headerfilename = " head.out " ;
109
FILE * headerfile;
110
111
static const char * bodyfilename = " body.html " ;
112
FILE * bodyfile;
113
114
struct curl_slist * headerlist = NULL;
115
static const char buf[] = " Expect: " ;
116
117
curl_global_init(CURL_GLOBAL_ALL);
118
curl = curl_easy_init();
119
headerlist = curl_slist_append(headerlist, buf);
120
if (curl)
121
{
122
// 拉取私有页面
123
curl_easy_setopt(curl, CURLOPT_URL, " http://hi.baidu.com/ea99/blog/item/c4e99e58d7ec9d86800a18a2.html " );
124
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
125
126
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
127
128
headerfile = fopen(headerfilename, " w " );
129
if (headerfile == NULL)
130
{
131
curl_easy_cleanup(curl);
132
curl_global_cleanup();
133
curl_slist_free_all(headerlist);
134
printf( " open head.out file failed!/n " );
135
return - 1 ;
136
}
137
138
bodyfile = fopen(bodyfilename, " w " );
139
if (bodyfile == NULL)
140
{
141
curl_easy_cleanup(curl);
142
curl_global_cleanup();
143
curl_slist_free_all(headerlist);
144
printf( " open body.html file failed!/n " );
145
return - 1 ;
146
}
147
148
curl_easy_setopt(curl,CURLOPT_WRITEHEADER, headerfile);
149
curl_easy_setopt(curl,CURLOPT_WRITEDATA,bodyfile);
150
151
curl_easy_setopt(curl,CURLOPT_COOKIEFILE, " cookie_login.txt " ); // 把第二步保存的cookie发送给服务器验证
152
153
#ifdef SKIP_PEER_VERIFICATION
154
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L );
155
#endif
156
157
#ifdef SKIP_HOSTNAME_VERFICATION
158
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L );
159
#endif
160
res = curl_easy_perform(curl);
161
/**/ /* always cleanup */
162
curl_easy_cleanup(curl);
163
/**/ /* free slist */
164
curl_slist_free_all(headerlist);
165
curl_global_cleanup();
166
if (headerfile != NULL)
167
fclose(headerfile);
168
169
if (bodyfile != NULL)
170
fclose(bodyfile);
171
172
}
173
return 0 ;
174
}
175
176
177
178
179
180
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/InBlock.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/InBlock.gif)
26
![](/Images/OutliningIndicators/InBlock.gif)
27
![](/Images/OutliningIndicators/InBlock.gif)
28
![](/Images/OutliningIndicators/InBlock.gif)
29
![](/Images/OutliningIndicators/InBlock.gif)
30
![](/Images/OutliningIndicators/InBlock.gif)
31
![](/Images/OutliningIndicators/InBlock.gif)
32
![](/Images/OutliningIndicators/InBlock.gif)
33
![](/Images/OutliningIndicators/InBlock.gif)
34
![](/Images/OutliningIndicators/InBlock.gif)
35
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
36
![](/Images/OutliningIndicators/InBlock.gif)
37
![](/Images/OutliningIndicators/InBlock.gif)
38
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
39
![](/Images/OutliningIndicators/InBlock.gif)
40
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
41
![](/Images/OutliningIndicators/InBlock.gif)
42
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
43
![](/Images/OutliningIndicators/None.gif)
44
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
45
![](/Images/OutliningIndicators/None.gif)
46
![](/Images/OutliningIndicators/None.gif)
47
![](/Images/OutliningIndicators/None.gif)
48
![](/Images/OutliningIndicators/None.gif)
49
![](/Images/OutliningIndicators/None.gif)
50
![](/Images/OutliningIndicators/None.gif)
51
![](/Images/OutliningIndicators/None.gif)
52
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
53
![](/Images/OutliningIndicators/InBlock.gif)
54
![](/Images/OutliningIndicators/InBlock.gif)
55
![](/Images/OutliningIndicators/InBlock.gif)
56
![](/Images/OutliningIndicators/InBlock.gif)
57
![](/Images/OutliningIndicators/InBlock.gif)
58
![](/Images/OutliningIndicators/InBlock.gif)
59
![](/Images/OutliningIndicators/InBlock.gif)
60
![](/Images/OutliningIndicators/InBlock.gif)
61
![](/Images/OutliningIndicators/InBlock.gif)
62
![](/Images/OutliningIndicators/InBlock.gif)
63
![](/Images/OutliningIndicators/InBlock.gif)
64
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
65
![](/Images/OutliningIndicators/InBlock.gif)
66
![](/Images/OutliningIndicators/InBlock.gif)
67
![](/Images/OutliningIndicators/InBlock.gif)
68
![](/Images/OutliningIndicators/InBlock.gif)
69
![](/Images/OutliningIndicators/InBlock.gif)
70
![](/Images/OutliningIndicators/InBlock.gif)
71
![](/Images/OutliningIndicators/InBlock.gif)
72
![](/Images/OutliningIndicators/InBlock.gif)
73
![](/Images/OutliningIndicators/InBlock.gif)
74
![](/Images/OutliningIndicators/InBlock.gif)
75
![](/Images/OutliningIndicators/InBlock.gif)
76
![](/Images/OutliningIndicators/InBlock.gif)
77
![](/Images/OutliningIndicators/InBlock.gif)
78
![](/Images/OutliningIndicators/InBlock.gif)
79
![](/Images/OutliningIndicators/InBlock.gif)
80
![](/Images/OutliningIndicators/InBlock.gif)
81
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
82
![](/Images/OutliningIndicators/InBlock.gif)
83
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
84
![](/Images/OutliningIndicators/InBlock.gif)
85
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
86
![](/Images/OutliningIndicators/InBlock.gif)
87
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
88
![](/Images/OutliningIndicators/None.gif)
89
![](/Images/OutliningIndicators/None.gif)
90
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
91
![](/Images/OutliningIndicators/None.gif)
92
![](/Images/OutliningIndicators/None.gif)
93
![](/Images/OutliningIndicators/None.gif)
94
![](/Images/OutliningIndicators/None.gif)
95
![](/Images/OutliningIndicators/None.gif)
96
![](/Images/OutliningIndicators/None.gif)
97
![](/Images/OutliningIndicators/None.gif)
98
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
99
![](/Images/OutliningIndicators/InBlock.gif)
100
![](/Images/OutliningIndicators/InBlock.gif)
101
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
102
![](/Images/OutliningIndicators/None.gif)
103
![](/Images/OutliningIndicators/None.gif)
104
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
105
![](/Images/OutliningIndicators/InBlock.gif)
106
![](/Images/OutliningIndicators/InBlock.gif)
107
![](/Images/OutliningIndicators/InBlock.gif)
108
![](/Images/OutliningIndicators/InBlock.gif)
109
![](/Images/OutliningIndicators/InBlock.gif)
110
![](/Images/OutliningIndicators/InBlock.gif)
111
![](/Images/OutliningIndicators/InBlock.gif)
112
![](/Images/OutliningIndicators/InBlock.gif)
113
![](/Images/OutliningIndicators/InBlock.gif)
114
![](/Images/OutliningIndicators/InBlock.gif)
115
![](/Images/OutliningIndicators/InBlock.gif)
116
![](/Images/OutliningIndicators/InBlock.gif)
117
![](/Images/OutliningIndicators/InBlock.gif)
118
![](/Images/OutliningIndicators/InBlock.gif)
119
![](/Images/OutliningIndicators/InBlock.gif)
120
![](/Images/OutliningIndicators/InBlock.gif)
121
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
122
![](/Images/OutliningIndicators/InBlock.gif)
123
![](/Images/OutliningIndicators/InBlock.gif)
124
![](/Images/OutliningIndicators/InBlock.gif)
125
![](/Images/OutliningIndicators/InBlock.gif)
126
![](/Images/OutliningIndicators/InBlock.gif)
127
![](/Images/OutliningIndicators/InBlock.gif)
128
![](/Images/OutliningIndicators/InBlock.gif)
129
![](/Images/OutliningIndicators/InBlock.gif)
130
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
131
![](/Images/OutliningIndicators/InBlock.gif)
132
![](/Images/OutliningIndicators/InBlock.gif)
133
![](/Images/OutliningIndicators/InBlock.gif)
134
![](/Images/OutliningIndicators/InBlock.gif)
135
![](/Images/OutliningIndicators/InBlock.gif)
136
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
137
![](/Images/OutliningIndicators/InBlock.gif)
138
![](/Images/OutliningIndicators/InBlock.gif)
139
![](/Images/OutliningIndicators/InBlock.gif)
140
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
141
![](/Images/OutliningIndicators/InBlock.gif)
142
![](/Images/OutliningIndicators/InBlock.gif)
143
![](/Images/OutliningIndicators/InBlock.gif)
144
![](/Images/OutliningIndicators/InBlock.gif)
145
![](/Images/OutliningIndicators/InBlock.gif)
146
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
147
![](/Images/OutliningIndicators/InBlock.gif)
148
![](/Images/OutliningIndicators/InBlock.gif)
149
![](/Images/OutliningIndicators/InBlock.gif)
150
![](/Images/OutliningIndicators/InBlock.gif)
151
![](/Images/OutliningIndicators/InBlock.gif)
152
![](/Images/OutliningIndicators/InBlock.gif)
153
![](/Images/OutliningIndicators/InBlock.gif)
154
![](/Images/OutliningIndicators/InBlock.gif)
155
![](/Images/OutliningIndicators/InBlock.gif)
156
![](/Images/OutliningIndicators/InBlock.gif)
157
![](/Images/OutliningIndicators/InBlock.gif)
158
![](/Images/OutliningIndicators/InBlock.gif)
159
![](/Images/OutliningIndicators/InBlock.gif)
160
![](/Images/OutliningIndicators/InBlock.gif)
161
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
162
![](/Images/OutliningIndicators/InBlock.gif)
163
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
164
![](/Images/OutliningIndicators/InBlock.gif)
165
![](/Images/OutliningIndicators/InBlock.gif)
166
![](/Images/OutliningIndicators/InBlock.gif)
167
![](/Images/OutliningIndicators/InBlock.gif)
168
![](/Images/OutliningIndicators/InBlock.gif)
169
![](/Images/OutliningIndicators/InBlock.gif)
170
![](/Images/OutliningIndicators/InBlock.gif)
171
![](/Images/OutliningIndicators/InBlock.gif)
172
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
173
![](/Images/OutliningIndicators/InBlock.gif)
174
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
175
![](/Images/OutliningIndicators/None.gif)
176
![](/Images/OutliningIndicators/None.gif)
177
![](/Images/OutliningIndicators/None.gif)
178
![](/Images/OutliningIndicators/None.gif)
179
![](/Images/OutliningIndicators/None.gif)
180
![](/Images/OutliningIndicators/None.gif)