91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 7.95MB
    文件類(lèi)型: .rar
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2023-10-07
  • 語(yǔ)言: C/C++
  • 標(biāo)簽: Socke??

資源簡(jiǎn)介

C++ Winsock 網(wǎng)絡(luò)編程 僅支持http協(xié)議 Socket進(jìn)行網(wǎng)絡(luò)連接 解析整個(gè)html代碼 寬度優(yōu)先搜索,像爬蟲(chóng)一樣遍歷網(wǎng)頁(yè) 正則表達(dá)式提取圖片URL 將圖片命名,保存在目錄下

資源截圖

代碼片段和文件信息


/*下載圖片?C++?Winsock?網(wǎng)絡(luò)編程*/

#define?_CRT_SECURE_NO_WARNINGS???//vs?2013用于忽略c語(yǔ)言安全性警告

#include?

#include?

#include?

#include?

#include?

#include?

#include?

#include?

#include?

#include?

#include?

using?namespace?std;

#pragma?comment(lib?“ws2_32.lib“)

char??host[500];

int?num?=?1;

char?othPath[800];

string?allHtml;

vector??photoUrl;

vector??comUrl;

map??mp;?//防止相同網(wǎng)址重復(fù)遍歷

SOCKET?sock;

bool?analyUrl(char?*url)?//僅支持http協(xié)議解析出主機(jī)和IP地址

{

char?*pos?=?strstr(url?“http://“);

if?(pos?==?NULL)

return?false;

else

pos?+=?7;

sscanf(pos?“%[^/]%s“?host?othPath);???//http://?后一直到/之前的是主機(jī)名

cout?<
return?true;

}





void?regexGetimage(string?&allHtml)??//C++11?正則表達(dá)式提取圖片url

{

smatch?mat;

regex?pattern(“src=\“(.*?\.jpg)\““);

string::const_iterator?start?=?allHtml.begin();

string::const_iterator?end?=?allHtml.end();

while?(regex_search(start?end?mat?pattern))

{

string?msg(mat[1].first?mat[1].second);

photoUrl.push_back(msg);

start?=?mat[0].second;

}

}



void?regexGetcom(string?&allHtml)?//提取網(wǎng)頁(yè)中的http://的url

{

smatch?mat;

//regex?pattern(“href=\“(.*?\.html)\““);

regex?pattern(“href=\“(http://[^\s‘\“]+)\““);

string::const_iterator?start?=?allHtml.begin();

string::const_iterator?end?=?allHtml.end();

while?(regex_search(start?end?mat?pattern))

{

string?msg(mat[1].first?mat[1].second);

comUrl.push_back(msg);

start?=?mat[0].second;

}

}

void?preConnect()??//socket進(jìn)行網(wǎng)絡(luò)連接

{

WSADATA?wd;

WSAStartup(MAKEWORD(2?2)?&wd);

sock?=?socket(AF_INET?SOCK_STREAM?0);

if?(sock?==?INVALID_SOCKET)

{

cout?<
return;

}

sockaddr_in?sa?=?{?AF_INET?};

int?n?=?bind(sock?(sockaddr*)&sa?sizeof(sa));

if?(n?==?SOCKET_ERROR)

{

cout?<
return;

}

struct?hostent??*p?=?gethostbyname(host);

if?(p?==?NULL)

{

cout?<
return;

}

sa.sin_port?=?htons(80);

memcpy(&sa.sin_addr?p->h_addr?4);//???with?some?problems????

//sa.sin_addr.S_un.S_addr?=?inet_addr(*(p->h_addr_list));

//cout?<h_addr_list)?<
n?=?connect(sock?(sockaddr*)&sa?sizeof(sa));

if?(n?==?SOCKET_ERROR)

{

cout?<
return;

}

//像服務(wù)器發(fā)送GET請(qǐng)求,下載圖片

string??reqInfo?=?“GET?“?+?(string)othPath?+?“?HTTP/1.1\r\nHost:?“?+?(string)host?+?“\r\nConnection:Close\r\n\r\n“;

if?(SOCKET_ERROR?==?send(sock?reqInfo.c_str()?reqInfo.size()?0))

{

cout?<

?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----

????I.A....?????40444??2018-09-22?21:29??Robot\Debug\img\?class=htt.jpg

????I.A....?????20104??2018-09-22?21:29??Robot\Debug\img\httpp1.img.jpg

????I.A....?????25833??2018-09-22?21:29??Robot\Debug\img\httpp2.img.jpg

????I.A....??????6231??2018-09-22?21:29??Robot\Debug\img\httpp3.img.jpg

????I.A....?????34512??2018-09-22?21:29??Robot\Debug\img\httpp4.img.jpg

????I.A....???????162??2018-09-22?21:29??Robot\Debug\img\httpp5.img.jpg

????I.A....????396800??2018-09-22?21:31??Robot\Debug\Robot.exe

????I.A....???1477212??2018-09-22?21:31??Robot\Debug\Robot.ilk

????I.A....???3623936??2018-09-22?21:31??Robot\Debug\Robot.pdb

????I.A....???2185280??2018-09-22?21:31??Robot\Robot\Debug\main.obj

????I.A....??????1979??2018-09-22?21:31??Robot\Robot\Debug\Robot.log

????I.A....???????714??2018-09-22?21:31??Robot\Robot\Debug\Robot.tlog\cl.command.1.tlog

????I.A....?????32216??2018-09-22?21:31??Robot\Robot\Debug\Robot.tlog\CL.read.1.tlog

????I.A....???????628??2018-09-22?21:31??Robot\Robot\Debug\Robot.tlog\CL.write.1.tlog

????I.A....??????1298??2018-09-22?21:31??Robot\Robot\Debug\Robot.tlog\link.command.1.tlog

????I.A....??????2782??2018-09-22?21:31??Robot\Robot\Debug\Robot.tlog\link.read.1.tlog

????I.A....???????606??2018-09-22?21:31??Robot\Robot\Debug\Robot.tlog\link.write.1.tlog

????I.A....???????196??2018-09-22?21:31??Robot\Robot\Debug\Robot.tlog\Robot.lastbuildstate

????I.A....????863232??2018-09-22?21:31??Robot\Robot\Debug\vc120.idb

????I.A....????831488??2018-09-22?21:31??Robot\Robot\Debug\vc120.pdb

?????文件???????5435??2018-09-22?21:31??Robot\Robot\main.cpp

?????文件???????4016??2018-09-22?01:44??Robot\Robot\Robot.vcxproj

????I.A....???????945??2018-09-22?01:44??Robot\Robot\Robot.vcxproj.filters

????I.A....??34865152??2018-09-22?21:31??Robot\Robot.sdf

????I.A....???????961??2018-09-22?01:43??Robot\Robot.sln

????I.A..H.?????19968??2018-09-22?21:31??Robot\Robot.v12.suo

????I..D...?????????0??2018-09-22?21:31??Robot\Robot\Debug\Robot.tlog

????I..D...?????????0??2018-09-22?21:29??Robot\Debug\img

????I..D...?????????0??2018-09-22?21:31??Robot\Robot\Debug

????I..D...?????????0??2018-09-22?01:44??Robot\Robot\img

............此處省略6個(gè)文件信息

評(píng)論

共有 條評(píng)論

相關(guān)資源