1-找到对应网页,F12查看源码,找到图片缩略图对应的内容,copy生成txt文件,作为读入文件
2-通过word的正则修改获得图片下载URL集(我这里直接使用了字符查找)
3-使用urlmon库里的downlode循环下载
```cpp
#include <tchar.h>
#include <iostream>
#include <urlmon.h>
#include <string>
#include <fstream>
#pragma comment(lib,"urlmon.lib")
using namespace std;
void testByChar()
{
fstream testByCharFile;
char c_old = ' ';char c_pre=' ';
testByCharFile.open("1.txt", ios::in);
string str1("");string str2("");string str3(""); string str4("");
bool getStr1 = false;bool getStr2 = false;bool getStr3 = false; bool getStr4 = false;
bool exit_inner = false; bool exit = false;
string str;
string url("");
int num = 1;
while (!exit) {
//--------------------------------------------------
//使用类正则逻辑进行链接修改
while (!exit_inner)
{
testByCharFile >> c_pre;
if (c_pre == '>'&&c_old == 'i') {
exit_inner = true; break;
}
if (c_pre == '@'&&c_old == '@') {
exit = true; break;
}
if (c_pre == '/'&&c_old == '/') getStr1 = true;
if (c_pre == 'i'&&c_old == '?') getStr1 = false;
if (getStr1)
{
str.assign(1, c_pre);
str1.append(str);
}
if (c_pre == 's'&&c_old == ';') getStr2 = true;
if (c_pre == 'a'&&c_old == '&') getStr2 = false;
if (getStr2)
{
str.assign(1, c_pre);
str2.append(str);
}
if (c_pre == 't'&&c_old == ';') getStr3 = true;
if (c_pre == 'q'&&c_old == '&') getStr3 = false;
if (getStr3)
{
str.assign(1, c_pre);
str3.append(str);
}
if (c_pre == 'A'&&c_old == '/') getStr4 = true;
if (c_pre == 'w'&&c_old == '_') getStr4 = false;
if (getStr4)
{
str.assign(1, c_pre);
str4.append(str);
}
c_old = c_pre;
}
if (!exit) {
url.append("https:/").append(str1).append(str2).append(str3).append("attname=").append(str4);
url.pop_back();
url.append(".jpg");
cout << url << endl;
//----------------------------------------------------------------------------------------
//通过链接下载对应文件
size_t len = url.length();//获取字符串长度
int nmlen = MultiByteToWideChar(CP_ACP, 0, url.c_str(), len + 1, NULL, 0);//如果函数运行成功,并且cchWideChar为零,
//返回值是接收到待转换字符串的缓冲区所需求的宽字符数大小。
wchar_t* buffer = new wchar_t[nmlen];
MultiByteToWideChar(CP_ACP, 0, url.c_str(), len + 1, buffer, nmlen);
string name = "E:";
name.append(to_string(num));
name.append(".jpg");
HRESULT hr = URLDownloadToFile(NULL, url.c_str(), _T(name.c_str()), 0, NULL);
num++;
if (hr == S_OK)
{
cout << "ok" << endl;
}
delete[] buffer;
str1.clear(); str2.clear(); str3.clear(); str4.clear(); url.clear();
}
exit_inner = false;
}
testByCharFile.close();
}
int main()
{
testByChar();
return 0;
}