好友
阅读权限20
听众
最后登录1970-1-1
|
很久之前写的,懒得整理了。有兴趣的可以看一看。
附上源码。
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <wininet.h>
#include <iostream>
#include <string.h>
#include <ctime>
//加入连接库
#pragma comment(lib, "wininet.lib")
using namespace std;
void mySleep(int msecond)
{
clock_t s;
s = clock();
while(clock() - s < msecond);
}
int main(int argc, char* argv[])
{
TCHAR buf[1025];
string sStr,sStr1,NextPage,HomePage;
TCHAR path[MAX_PATH];
DWORD num;
int i,j,j1;
//打开
HINTERNET hinet = InternetOpen(_TEXT("Microsoft Internet Explorer"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_INVALID_PORT_NUMBER);
// GetTempPath(MAX_PATH, path);
// strcat(path, "/t.txt");
//获取文件句柄
HomePage = "https://www.qu.la/book/8909/";
NextPage = HomePage + "3607170.html"; //name
BEGIN:
HINTERNET hurl = InternetOpenUrl(hinet, NextPage.c_str(), NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0);
// FILE* i = fopen(path, "wb");
//从internet下载文件内容
sStr = "";
ZeroMemory(buf, 1025);
while(TRUE == InternetReadFile(hurl, buf, 1024, &num) && num>0)
{
// fwrite(buf, 1, num, i);
// cout << buf << endl;
// sStr1 = buf;
// sStr = sStr + sStr1;
buf[num] = '\0';
sStr = sStr + buf;
// cout << "" << endl;
}
// fclose(i);
// cout << sStr << endl << "====================================" << endl;
//使用完毕文件句柄和关闭连接
InternetCloseHandle(hurl);
//获取下一页地址
i = sStr.find(_T("下一章"));
i = sStr.rfind("href=",i);
i = i + 6;
j = sStr.find("\"",i+2);
NextPage = sStr.substr(i,j-i);
// cout << endl << "Next Page Addr:" << NextPage << endl << endl;
// cout << endl << "下一页地址:" << sizeof(NextPage) << endl << endl;
//获取章节名称<title>
i = sStr.find("bookname");
i = sStr.find("<h1>",i);
i = i + 4;
j = sStr.find("</h1>",i+2);
cout << sStr.substr(i,j-i) << endl ;
//获取本页内容
i = sStr.find("id=\"content");
i = sStr.find(">",i);
i = i + 1;
j = sStr.find("</div>",i);
j = j - i;
if(NextPage.length()<15)
{
NextPage = HomePage + NextPage;
cout << sStr.substr(i,j) << endl;
mySleep(1000);
goto BEGIN;
}
cout << sStr.substr(i,j) << endl;
InternetCloseHandle(hinet);
End1:
return 0;
}
如果您觉得有用,给点免费的热心值呗 |
免费评分
-
查看全部评分
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|