純C配合Wget編寫多平臺粉絲數(shù)量實時統(tǒng)計程序,b站 博客等

## 視頻講
視頻講解:[傳送門]
靈感來源:av84354171
## 代碼下載:
github:[https://github.com/Ikaros-521/using-C-to-get-user-s-fans]
碼云:[https://gitee.com/ikaros-521/using-C-to-get-user-s-fans]
Linux的話,去掉頭文件conio.h,getch(),稍加改動就行了
用到的工具:[Wget](http://www.gnu.org/software/wget/)
## 效果展示

相關(guān)打印可以修改 mix.c 自行優(yōu)化

## 編譯
gcc mix.c -o mix
## 運行
直接運行mix.exe 或 打開cmd,cd到工作目錄,輸入 mix.exe 運行(如果生成文件后,程序沒有自動刪掉,請手動刪除)

### 用戶信息填寫
**user_info.conf**
```bash
speed:1
bilibili:uid
cnblogs:id
csdn:id
gitee:id
github:id
zhihu:id
```
speed速度就是循環(huán)的速度。
其他分別對應(yīng)各平臺的id,如果沒有也隨便填一個,不需要可以在 mix.c 中注釋掉對應(yīng)平臺。
## 代碼
### mix.c
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
void bilibili(char* str); // 嗶哩嗶哩
void cnblogs(char* str); // 博客園
void csdn(char* str); // CSDN
void gitee(char* str); // 碼云
void github(char* str); // GitHub
void zhihu(char* str); // 知乎
int main()
{
double speed = 1;
char id_bilibili[20] = {};
char id_cnblogs[80] = {};
char id_csdn[40] = {};
char id_gitee[40] = {};
char id_github[40] = {};
char id_zhihu[80] = {};
FILE* f = NULL;
// 打開配置文件
f = fopen("user_info.conf", "r");
if (f == NULL)
{
printf("File user_info.conf access error! press any key to exit \n");
getch();
exit(0);
}
int i = 0;
fscanf(f, "speed:%lf\nbilibili:%s\ncnblogs:%s\ncsdn:%s\ngitee:%s\ngithub:%s\nzhihu:%s\n", &speed, id_bilibili, id_cnblogs, id_csdn, id_gitee, id_github, id_zhihu);
printf("---------- config ----------\nspeed:%lf\nbilibili:%s\ncnblogs:%s\ncsdn:%s\ngitee:%s\ngithub:%s\nzhihu:%s\n---------------------------\n", speed, id_bilibili, id_cnblogs, id_csdn, id_gitee, id_github, id_zhihu);
speed *= 6e8;
re:
// 配置文件必須保證有數(shù)據(jù),不需要的函數(shù)可以注釋掉。
bilibili(id_bilibili); // 嗶哩嗶哩
cnblogs(id_cnblogs); // 博客園
csdn(id_csdn); // CSDN
gitee(id_gitee); // 碼云
//github(id_github); // GitHub
zhihu(id_zhihu); // 知乎
// 循環(huán)耗時
for (i = 0;i < speed;i++);
// 清屏
system("cls");
goto re;
return 0;
}
// 嗶哩嗶哩
void bilibili(char* str)
{
//printf("in bilibili");
char id[20] = {};
char cmd[100] = {};
FILE* fp = NULL;
char buf[4096] = {};
char fans[10] = {};
int i = 0;
strcpy(id, str);
sprintf(cmd ,"..\\wget.exe -q https://api.bilibili.com/x/relation/stat?vmid=%s -O bilibili.txt", id);
system(cmd);
fp = fopen("bilibili.txt", "r");
if (fp == NULL)
{
printf("File bilibili.txt access error! press any key to exit \n");
getch();
exit(0);
}
i = 0;
while(1)
{
fscanf(fp, "%s", buf);
char *temp = strstr(buf, "follower");
if(temp == NULL)
{
memset(buf, 0, sizeof(buf));
continue;
}
temp += 10;
while(1)
{
if(temp[i] == '}' || temp[i] == '\0' || temp[i] == '\n')
{
break;
}
fans[i] = temp[i];
i++;
}
printf("bilibili:%s\n", fans);
memset(buf, 0, sizeof(buf));
memset(fans, 0, sizeof(fans));
temp = NULL;
break;
}
fclose(fp);
fp = NULL;
memset(cmd, 0, sizeof(cmd));
sprintf(cmd, "del \"bilibili.txt\"");
system(cmd);
memset(cmd, 0, sizeof(cmd));
}
// 博客園
void cnblogs(char* str)
{
char id[80] = {};
char cmd[100] = {};
FILE* fp = NULL;
char *buf = malloc(4096);
char fans[10] = {};
int i = 0;
strcpy(id, str);
sprintf(cmd ,"..\\wget.exe -q https://www.cnblogs.com/%s/ajax/news.aspx -O cnblogs.txt", id);
system(cmd);
fp = fopen("cnblogs.txt", "r");
if (fp == NULL)
{
printf("File cnblogs.txt access error! press any key to exit \n");
getch();
exit(0);
}
i = 0;
while(1)
{
fscanf(fp, "%s", buf);
char *temp = strstr(buf, "follower");
if(temp == NULL)
{
memset(buf, 0, sizeof(buf));
continue;
}
memset(buf, 0, sizeof(buf));
fscanf(fp, "%s", buf);
sprintf(fans, "%s", buf);
printf("cnblogs :%s\n", fans);
memset(buf, 0, sizeof(buf));
memset(fans, 0, sizeof(fans));
temp = NULL;
break;
}
fclose(fp);
fp = NULL;
memset(cmd, 0, sizeof(cmd));
sprintf(cmd, "del cnblogs.txt");
system(cmd);
memset(cmd, 0, sizeof(cmd));
}
// CSDN
void csdn(char* str)
{
char id[40] = {};
char cmd[100] = {};
FILE* fp = NULL;
char *buf = malloc(4096);
char fans[10] = {};
int i = 0;
strcpy(id, str);
sprintf(cmd ,"..\\wget.exe -q https://blog.csdn.net/%s -O csdn.txt", id);
system(cmd);
fp = fopen("csdn.txt", "r");
if (fp == NULL)
{
printf("File csdn.txt access error! press any key to exit \n");
getch();
exit(0);
}
i = 0;
while(1)
{
fscanf(fp, "%s", buf);
char *temp = strstr(buf, "id=\"fan\">");
if(temp == NULL)
{
memset(buf, 0, sizeof(buf));
continue;
}
temp += 9;
while(1)
{
if(temp[i] == '<' || temp[i] == '\0' || temp[i] == '\n')
{
break;
}
fans[i] = temp[i];
i++;
}
printf("CSDN ? ?:%s\n", fans);
memset(buf, 0, sizeof(buf));
memset(fans, 0, sizeof(fans));
temp = NULL;
break;
}
fclose(fp);
fp = NULL;
memset(cmd, 0, sizeof(cmd));
sprintf(cmd, "del csdn.txt");
system(cmd);
memset(cmd, 0, sizeof(cmd));
}
// 碼云
void gitee(char* str)
{
char id[40] = {};
char cmd[100] = {};
FILE* fp = NULL;
char *buf = malloc(4096);
char fans[10] = {};
int i = 0;
int flag = 0;
strcpy(id, str);
sprintf(cmd ,"..\\wget.exe -q https://gitee.com/%s/followers -O gitee.txt", id);
system(cmd);
fp = fopen("gitee.txt", "r");
if (fp == NULL)
{
printf("File gitee.txt access error! press any key to exit \n");
getch();
exit(0);
}
i = 0;
flag = 0;
while(1)
{
fscanf(fp, "%s", buf);
char *temp = strstr(buf, "social-count");
if(temp == NULL)
{
memset(buf, 0, sizeof(buf));
continue;
}
if(flag == 0 || flag == 1)
{
flag++;
memset(buf, 0, sizeof(buf));
continue;
}
temp += 14;
while(1)
{
if(temp[i] == '<' || temp[i] == '\0' || temp[i] == '\n')
{
break;
}
fans[i] = temp[i];
i++;
}
printf("gitee ? :%s\n", fans);
memset(buf, 0, sizeof(buf));
memset(fans, 0, sizeof(fans));
temp = NULL;
break;
}
fclose(fp);
fp = NULL;
memset(cmd, 0, sizeof(cmd));
sprintf(cmd, "del gitee.txt");
system(cmd);
memset(cmd, 0, sizeof(cmd));
}
// GitHub
void github(char* str)
{
char id[40] = {};
char cmd[100] = {};
FILE* fp = NULL;
char *buf = malloc(4096);
char fans[10] = {};
int i = 0;
int flag = 0;
strcpy(id, str);
sprintf(cmd ,"..\\wget.exe -q ?https://github.com/%s -O github.txt", id);
system(cmd);
fp = fopen("github.txt", "r");
if (fp == NULL)
{
printf("File github.txt access error! press any key to exit \n");
getch();
exit(0);
}
i = 0;
flag = 0;
while(1)
{
fscanf(fp, "%s", buf);
char *temp = strstr(buf, "hide-sm");
if(temp == NULL)
{
memset(buf, 0, sizeof(buf));
continue;
}
if(flag == 0 || flag == 1 || flag == 2)
{
flag++;
memset(buf, 0, sizeof(buf));
continue;
}
memset(buf, 0, sizeof(buf));
fscanf(fp, "%s", buf);
memset(buf, 0, sizeof(buf));
fscanf(fp, "%s", buf);
sprintf(fans, "%s", buf);
printf("GitHub ?:%s\n", fans);
memset(buf, 0, sizeof(buf));
memset(fans, 0, sizeof(fans));
temp = NULL;
break;
}
fclose(fp);
fp = NULL;
memset(cmd, 0, sizeof(cmd));
sprintf(cmd, "del github.txt");
system(cmd);
memset(cmd, 0, sizeof(cmd));
}
// 知乎
void zhihu(char* str)
{
char id[80] = {};
char cmd[100] = {};
FILE* fp = NULL;
char *buf = malloc(4096);
char fans[10] = {};
int i = 0;
int flag = 0;
strcpy(id, str);
sprintf(cmd ,"..\\wget.exe -q https://www.zhihu.com/people/%s -O zhihu.txt", id);
system(cmd);
fp = fopen("zhihu.txt", "r");
if (fp == NULL)
{
printf("File zhihu.txt access error! press any key to exit \n");
getch();
exit(0);
}
flag = 0;
i = 0;
while(1)
{
fscanf(fp, "%s", buf);
char *temp = strstr(buf, "title=\"");
if(temp == NULL)
{
memset(buf, 0, sizeof(buf));
continue;
}
if(flag == 0 || flag == 1)
{
flag++;
memset(buf, 0, sizeof(buf));
continue;
}
temp += 7;
while(1)
{
if(temp[i] == '"' || temp[i] == '\0' || temp[i] == '\n')
{
break;
}
fans[i] = temp[i];
i++;
}
printf("zhihu ? :%s\n", fans);
memset(buf, 0, sizeof(buf));
memset(fans, 0, sizeof(fans));
temp = NULL;
break;
}
fclose(fp);
fp = NULL;
memset(cmd, 0, sizeof(cmd));
sprintf(cmd, "del zhihu.txt");
system(cmd);
memset(cmd, 0, sizeof(cmd));
}
```