之前讨论过网页爬虫, 本文也是沿用之前思路。 以我的CSDN博客为例, 来获取访问量和积分信息, 代码如下:
#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.csdn.net"; // 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.sin_addr.S_un.S_addr=inet_addr(pIPAddr);
webServerAddr.sin_port = htons(80);
1万+




被折叠的 条评论
为什么被折叠?



