static Image *ReadURLImage(const ImageInfo *image_info,ExceptionInfo *exception) { #define MaxBufferExtent 8192 char filename[MaxTextExtent]; FILE *file; Image *image; ImageInfo *read_info; int unique_file; image=(Image *) NULL; read_info=CloneImageInfo(image_info); SetImageInfoBlob(read_info,(void *) NULL,0); file=(FILE *) NULL; unique_file=AcquireUniqueFileResource(read_info->filename); if (unique_file != -1) file=fdopen(unique_file,"wb"); if ((unique_file == -1) || (file == (FILE *) NULL)) { ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile", read_info->filename); read_info=DestroyImageInfo(read_info); return((Image *) NULL); } (void) CopyMagickString(filename,image_info->magick,MaxTextExtent); (void) ConcatenateMagickString(filename,":",MaxTextExtent); LocaleLower(filename); (void) ConcatenateMagickString(filename,image_info->filename,MaxTextExtent); if (LocaleCompare(read_info->magick,"file") == 0) { (void) RelinquishUniqueFileResource(read_info->filename); unique_file=(-1); (void) CopyMagickString(read_info->filename,image_info->filename+2, MaxTextExtent); } #if defined(MAGICKCORE_WINDOWS_SUPPORT) && \ !(defined(__MINGW32__) || defined(__MINGW64__)) (void) fclose(file); if (URLDownloadToFile(NULL,filename,read_info->filename,0,NULL) != S_OK) { ThrowFileException(exception,FileOpenError,"UnableToOpenFile", filename); (void) RelinquishUniqueFileResource(read_info->filename); read_info=DestroyImageInfo(read_info); return((Image *) NULL); } #else #if defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_FTP_ENABLED) if (LocaleCompare(read_info->magick,"ftp") == 0) { void *context; xmlNanoFTPInit(); context=xmlNanoFTPNewCtxt(filename); if (context != (void *) NULL) { if (xmlNanoFTPConnect(context) >= 0) (void) xmlNanoFTPGet(context,GetFTPData,(void *) file, (char *) NULL); (void) xmlNanoFTPClose(context); } } #endif #if defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_HTTP_ENABLED) if (LocaleCompare(read_info->magick,"http") == 0) { char buffer[MaxBufferExtent], *type; int bytes; void *context; type=(char *) NULL; context=xmlNanoHTTPMethod(filename,(const char *) NULL, (const char *) NULL,&type,(const char *) NULL,0); if (context != (void *) NULL) { ssize_t count; while ((bytes=xmlNanoHTTPRead(context,buffer,MaxBufferExtent)) > 0) count=(ssize_t) fwrite(buffer,bytes,1,file); (void) count; xmlNanoHTTPClose(context); xmlFree(type); xmlNanoHTTPCleanup(); } } #endif (void) fclose(file); #endif { ExceptionInfo *sans; ImageInfo *clone_info; /* Guess image format from URL. */ clone_info=CloneImageInfo(image_info); sans=AcquireExceptionInfo(); (void) SetImageInfo(clone_info,0,sans); (void) CopyMagickString(read_info->magick,clone_info->magick,MaxTextExtent); clone_info=DestroyImageInfo(clone_info); sans=DestroyExceptionInfo(sans); } image=ReadImage(read_info,exception); if (unique_file != -1) (void) RelinquishUniqueFileResource(read_info->filename); read_info=DestroyImageInfo(read_info); if (image != (Image *) NULL) GetPathComponent(image_info->filename,TailPath,image->filename); else { (void) ThrowMagickException(exception,GetMagickModule(),CoderError, "NoDataReturned","`%s'",filename); return((Image *) NULL); } return(GetFirstImageInList(image)); }
void FtpHelper::GetFile(string_t ftpAddr, string_t fileName) { url addr(ftpAddr); URLDownloadToFile(NULL, &ftpAddr.c_str()[0], (LPCWSTR)&fileName.c_str()[0], 0, NULL); }
int _tmain(int argc, _TCHAR* argv[]) { /* add valid user */ valid_user.Add(_T("mr_timon")); valid_user.Add(_T("mr_pumbaa")); valid_user.Add(_T("star_patrick")); valid_user.Add(_T("乐乐是我的哦")); valid_user.Add(_T("457800643xc")); valid_user.Add(_T("lingzhiji服饰旗舰店")); valid_user.Add(_T("呢好美")); //valid_user.Add(_T("star")); //valid_user.Add(_T("lele")); if(checkUser(argv[2])){ std::cout << std::endl << std::endl << " you are not a valid user! " << std::endl << std::endl << std::endl; return 0; } CString URL; CString url_date; CString url_spm = _T("spm=1.7274553.1997520841.1"); CString url_keyWord ; CString url_option = _T("commend=all&ssid=s5-e&search_type=item&sourceId=tb.index"); CString url_head = _T("http://s.taobao.com/search?"); CString url_page; CString filePath = _T("dist"); //CString string_keyWord = _T("儿童防紫外线帽子"); //CString string_id = _T("mr_timon"); CString string_keyWord = argv[1]; CString string_id = argv[2]; url_date = _T("initiative_id=tbindexz_") + generateUrlDate(); url_keyWord = _T("q=") + generateUrlKeyWord(string_keyWord); for(int i = 1; i <= 100; i++){ url_page = generateUrlPage(i); if((i - 1)%10 == 0){ std::cout << " searching"; for(int j = 0; j < i/10; j++){ std::cout << "."; } std::cout << std::endl; } if(i != 1){ URL = url_head + url_keyWord + _T("&") + url_spm + _T("&") + url_option+ _T("&") + url_date + _T("&") + url_page; }else{ URL = url_head + url_keyWord + _T("&") + url_spm + _T("&") + url_option+ _T("&") + url_date; } /* 这里有资源链接的话,可以把对应的资源下载下来 */ //URL = _T("http://www.jojomamanbebe.co.uk/products/images/large/B2755C.jpg"); HRESULT result = URLDownloadToFile(0, URL, filePath, 0, NULL); if(result == S_OK){ //std::cout << "down\n"; if(!searchLocation(filePath,string_id)){ std::cout << " page = " << i << std::endl << std::endl << std::endl; break; }else{ if(i == 100) std::cout << std::endl << std::endl << "************* sorry,we don't have found it *************" << std::endl << std::endl << std::endl ; } }else{ std::cout << "URLDownloadToFile failed\n"; return 1; } } //std::cout << "real_url = " << URL << std::endl; std::ofstream fout("currentURL.txt"); fout << URL; fout.flush(); fout.close(); //getchar(); return 0; }