之前讨论过网页爬虫, 本文也是沿用之前思路。 以我的优快云博客为例, 来获取访问量和积分信息, 代码如下:
#include <stdio.h>
#include <winsock2.h>
#include <time.h>
#include <iostream>
#include <string>
#pragma comment(lib, "ws2_32.lib")
using namespace std;
void unixTime2Str(int n, char strTime[], int bufLen)
{
struct tm tm = *localtime((time_t *)&n);
strftime(strTime, bufLen - 1, "%Y-%m-%d %H:%M:%S", &tm);
strTime[bufLen - 1] = '\0';
}
int main()
{
HOSTENT *pHost = NULL;
WSADATA wsaData;
WSAStartup(MAKEWORD(1,1), &wsaData);
char szWeb[] = "blog.youkuaiyun.com"; // csdn
if(NULL == pHost)
{
pHost = gethostbyname(szWeb);
}
const char* pIPAddr = inet_ntoa(*((struct in_addr *)pHost->h_addr)) ;
printf("web server ip is : %s", pIPAddr);
SOCKADDR_IN webServerAddr;
webServerAddr.sin_family = AF_INET;
webServerAddr.