如何使用C++下载网页的HTML内容
How can I download the HTML contents of a webpage using C++
这是我的代码
#include <iostream>
#include <Windows.h>
#include <WinInet.h>
using namespace std;
int main()
{
HINTERNET hSession, hURL;
char* Buffer = new char[1024];
DWORD BufferLen, BytesWritten;
HANDLE FileHandle;
hSession = InternetOpenA(NULL, 0, NULL, NULL, 0);
hURL = InternetOpenUrlA(hSession, "http://www.google.co.uk", NULL, 0, 0, 0);
FileHandle = CreateFileA("C:\temp.txt", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
BytesWritten = 0;
do
{
InternetReadFile(hURL, Buffer, 1024, &BufferLen);
WriteFile(FileHandle, Buffer, BufferLen, &BytesWritten, NULL);
} while (BufferLen != 0);
CloseHandle(FileHandle);
InternetCloseHandle(hURL);
InternetCloseHandle(hSession);
ShellExecuteA(0, "open", "C:\temp.txt", NULL, NULL, 1);
cout << "Operation complete!";
system("PAUSE");
return 0;
}
以下是我遇到的错误
error LNK2019: unresolved external symbol __imp__InternetOpenA@20 referenced in function _main
error LNK2019: unresolved external symbol __imp__InternetCloseHandle@4 referenced in function _main
error LNK2019: unresolved external symbol __imp__InternetOpenUrlA@24 referenced in function _main
error LNK2019: unresolved external symbol __imp__InternetReadFile@16 referenced in function _main
我不明白我哪里错了。我已经导入了Wininet.h和Windows.h。为什么它仍然无法找到这些功能?当做
您所做的是包含头文件,但不链接到实现它的实际代码。
在项目中包含Wininet.lib。
项目->属性->配置属性->链接器->输入->附加依赖项
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- 你能重载对象变量名本身返回的内容吗
- 如何将内容数组写入文本文件?
- 试图让变量检查数组中的某些内容
- initializer_list中字符串的内容为何为空
- C++宏忽略之后的内容
- 如何通过套接字将文本文件的内容从服务器发送到客户端
- 有没有办法从非C/C++文件中读取C++原始字符串文字的内容
- 使用 ReadTheOrg 将识字程序导出为 HTML 时保留源块的内容
- C++ libcurl - 无法从 URL 检索整个 html 内容
- 如何使用c++只查找特定HTML标记的内容
- 如何使用C++下载网页的HTML内容
- 如何从流中加载html内容,然后如何创建样式表以在预览窗格中显示html文件(如html预览处理程序)
- 试图获取位于tar文件中的html文件的内容
- 更新进程地址空间中的HTML内容
- QWebView 无法显示通过 javascript 设置的外部图像内容 $( "#<node_name>" ).html(<html_content>)
- 用于获取HTML表内容的正则表达式
- 实时uri翻译的HTML内容在C/ c++
- 如何在CGI应用程序中解析HTML文件并修改其内容?C++
- 在WIN32中显示没有窗口的HTML内容