當前位置:首頁 » 密碼管理 » c訪問網站

c訪問網站

發布時間: 2022-08-04 18:53:47

c語言能寫一個訪問網站的程序嗎

你要的是一個瀏覽器吧。 一個網址的內容被下下來是一堆源碼,要是能達到在網頁上點擊,輸入字元,點確定的功能,需要瀏覽器的展現,渲染,執行JavaScript等,你說的不就是一個瀏覽器嗎

❷ 如何用C語言打開網站

參考代碼如下:

#include<windows.h>
intmain(void)
{
ShellExecute(NULL,"open","http://www..com",NULL,NULL,SW_MINIMIZE);
return0;
}

例子中是最小化打開的,還可以是最大化SW_MAXIMIZE,隱藏SW_HIDE等。

❸ 怎麼用C++訪問網頁

用C++hinternet這個API可以實現訪問網頁
你要是想做個瀏覽器哦可以用內置的OCXWEB控制項

#include<stdio.h>
#include<Windows.h>
#include<Wininet.h>

#pragmacomment(lib,"Wininet.lib")

#defineURLL"http://www..com/"
#defineUSER_AGENTL"Mozilla/4.0(compatible;MSIE8.0;WindowsNT5.1;Trident/4.0;.NET4.0C;.NET4.0E;.NETCLR2.0.50727)"

boolOpenUrl()
{
HINTERNEThInternet,hInternetUrl;
hInternet=InternetOpen(USER_AGENT,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,NULL);
if(!hInternet){
wprintf(L"InternetOpenerror:%d ",GetLastError());
returnfalse;
}
hInternetUrl=InternetOpenUrl(hInternet,URL,NULL,0,INTERNET_FLAG_HYPERLINK,NULL);
if(!hInternetUrl){
wprintf(L"InternetOpenUrlerror:%d ",GetLastError());
InternetCloseHandle(hInternet);
returnfalse;
}
InternetCloseHandle(hInternetUrl);
InternetCloseHandle(hInternet);
returntrue;
}

intmain()
{
OpenUrl();
return0;
}

❹ C語言如何用代碼模擬手機去訪問手機網站抓取數據

WebClient client = new WebClient ();
client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
更改user-agent為手機瀏覽器的。
模擬谷歌Android:
user-agent="Mozilla/5.0 (linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
模擬蘋果iPhone:
user-agent="Mozilla/5.0 (iPad; U; CPU OS 3_2_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B500 Safari/531.21.10"

❺ 用c語言打開指定網頁,(要能登陸帳號)

打開指定網頁,可以有很多方式,比如shellexecute函數就可以直接打開你需要的網頁。
關於登陸用戶名密碼,個人感覺應該是循環遍歷當前頁面的所有控制項,根據控制項名,來選擇登陸和密碼輸入框。至於驗證碼,這個問題,解決難度有點高。暫時沒想到什麼好的方式,如果沒錯的話,應該是引用三方插件,或者是對圖片進行分析。要求相對比較高。
(PS:要知道,驗證碼的目的就是防止用戶只用流氓軟體進行登陸,造成損失不必要的資源。)
個人願意配合做開發。

❻ Linux中怎麼用C語言打開網頁

給你一個哈,我自己調試好的,並且加了詳細注釋~~記得給分啊,我沒分問問題了~

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <string.h>
#include <stdarg.h>
#include <netdb.h>
#include <setjmp.h>
#include <signal.h>

/*gethostbyname 超時返回
這里使用的辦法是設置一個時鍾,如果gethostbyname在指定的時間內尚未返回,
時鍾會強制其返回,得到的返回值顯然是空指針,等價於告訴用戶主機未連如互聯網或者該域名無法解析。*/
static sigjmp_buf jmpbuf;
static void alarm_func() //該函數執行之後會執行跳轉
{
siglongjmp(jmpbuf, 1);
}

static struct hostent *gngethostbyname(char *HostName, int timeout)
{
struct hostent *lpHostEnt;

signal(SIGALRM, alarm_func); //接受alarm信號,然後調用函數
if(sigsetjmp(jmpbuf, 1) != 0)//跳轉目的地
{
alarm(0);//timout
signal(SIGALRM, SIG_IGN);
return NULL;
}
alarm(timeout);//setting alarm
printf("\nwill gethost!\n");
lpHostEnt = gethostbyname(HostName);
signal(SIGALRM, SIG_IGN);

return lpHostEnt;
}

/*(linux socket編程實現connect超時的一種方法
創建套接字,將其設置成非阻塞狀態。
調用connect連接對端主機,如果失敗,判斷當時的errno是否為EINPROGRESS,也就是說是不是連接正在進行中,如果是,轉到步驟3,如果不是,返回錯誤。
用select在指定的超時時間內監聽套接字的寫就緒事件,如果select有監聽到,證明連接成功,否則連接失敗。*/

int main(int argc, char *argv[])
{
//最好檢查一下參數,要求傳入3個參數 URL PORT TIMEOUT(connect && send && recv 3個參數的超時)
int fd, retval,res,error;
struct sockaddr_in addr;
struct timeval timeo = {15, 0}; //time ou struct
struct hostent *site;
socklen_t len = sizeof(timeo);
fd_set set;
fd = socket(AF_INET, SOCK_STREAM, 0);
if (argc == 4)
timeo.tv_sec = atoi(argv[3]);
site=gngethostbyname(argv[1],3); //解析域名的超時設置,測試域名超時,可以寫一個可以ping的通但是沒有辦法解析域名
//的IP地址到resolv.conf裡面,然後加上一個默認路由,直接PING一個網路,就能發現如果不加超時機制就會一直卡在那裡
if(NULL == site)
{
printf("\ncan not find the site!\n");
return -2;
}
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); //設置為非阻塞模式
addr.sin_family = AF_INET;
//addr.sin_addr.s_addr = inet_addr(argv[1]);
memcpy(&addr.sin_addr, site->h_addr_list[0], site->h_length);
addr.sin_port = htons(atoi(argv[2]));
printf("%d\n", time(NULL));
/*if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0) {
printf("connected1\n");
// return 0;
}*/
//res=connect(fd, (struct sockaddr*)&addr, sizeof(addr));
//printf("\nconnect result:[%d]\n",res);
if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) != 0)
{
//調用一次系統函數失敗後直接看errno,確定是什麼問題,下面的代碼可以實現在沒有默認路由的情況下直接返回失敗.
if (errno != EINPROGRESS) {
printf("connect:normal network unreach!!");
return -1;
}
printf("\nwill select\n");
FD_ZERO(&set);/*將set清零使集合中不含任何fd*/
FD_SET(fd,&set); /*將一個給定的文件描述符加入集合之中*/
retval = select(fd + 1, NULL, &set, NULL, &timeo);
if (retval == -1) {
printf("select");
return -1;
} else if(retval == 0) {
printf("timeout\n"); //這樣的select等於是變成了再timeout時間內是阻塞模式,超過timeout就直接返回
printf("%d\n", time(NULL));
return 0;
}
else
{
printf("connected--->:[%d]\n",retval);
getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, (socklen_t *)&len); //判斷在connected成功之後,獲取套介面目前的一些信息來判斷是否真的是連接上了,返回0表示真的連上了
printf("error--->:[%d]\n",error);

if(0!=error)
return -1;
}
}

int ul = 0;
ioctl(fd, FIONBIO, &ul); //設置為阻塞模式
//return 0;
setsockopt(fd,SOL_SOCKET,SO_SNDTIMEO,(char *)&timeo,sizeof(timeo));
setsockopt(fd,SOL_SOCKET,SO_RCVTIMEO,(char *)&timeo,sizeof(timeo));
printf("\nbefore\n");
sleep(5); //在sleep 5的時候,拔掉網線就可以測試出recv超時的功能,如果不加recv 的超時功能,拔掉網線後就會一直卡在那裡,當然你在實際應用的時候沒必要加這個
printf("\nafter\n");
char *msg="GET / HTTP/1.0\r\n\r\n";
if( send(fd, msg, strlen(msg), 0)<0 )
{
printf("error in send msg\n");
exit(1);
}
int i=0;
char buf[1000];

while((recv(fd,buf,1000,MSG_WAITALL))>0)
{
printf("[%d]:[%s]",i,buf);
i++;
}
printf("\n------end---------\n");
close(fd);
return;
}

❼ c語言如何使用libcurl訪問一個網頁,得到源碼後返回給一個字元串變數

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<curl/curl.h>

structstring{
char*ptr;
size_tlen;
};

voidinit_string(structstring*s){
s->len=0;
s->ptr=malloc(s->len+1);
if(s->ptr==NULL){
fprintf(stderr,"malloc()failed ");
exit(EXIT_FAILURE);
}
s->ptr[0]='';
}

size_twritefunc(void*ptr,size_tsize,size_tnmemb,structstring*s)
{
size_tnew_len=s->len+size*nmemb;
s->ptr=realloc(s->ptr,new_len+1);
if(s->ptr==NULL){
fprintf(stderr,"realloc()failed ");
exit(EXIT_FAILURE);
}
memcpy(s->ptr+s->len,ptr,size*nmemb);
s->ptr[new_len]='';
s->len=new_len;

returnsize*nmemb;
}

intmain(void)
{
CURL*curl;
CURLcoderes;

curl=curl_easy_init();
if(curl){
structstrings;
init_string(&s);

curl_easy_setopt(curl,CURLOPT_URL,"curl.haxx.se");
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,writefunc);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,&s);
res=curl_easy_perform(curl);

printf("%s ",s.ptr);
free(s.ptr);

/*alwayscleanup*/
curl_easy_cleanup(curl);
}
return0;
}

❽ C類ip地址 發布的網頁 怎麼訪問

只要你的網站發布了,不管電腦IP是A類、B類,還是C類都可以訪問的。
可以在路由器中設置的。像掛到伺服器上一樣的效果!

❾ 如何在C或C++程序中打開一個網址

C C++語言本身並沒有這個功能,倒是在MFC 或者 調用操作系統API可以實現。
ShellExecute(NULL,"open","http://www..com",NULL,NULL,SW_SHOW);
要包含頭文件windows.h

❿ 在c\c++中如何調用IE訪問指定網站

很簡單,
進行系統調用就好了,
system("\"C:\Program Files\Internet Explorer\IEXPLORE.EXE\" http://www..com");

注意引號,寫上引號。
上面可能寫錯了,這樣寫:
system("\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\" http://www..com");

或者你現在環境變數PATH裡面加上C:\Program Files\Internet Explorer
然後執行IEXPLORE.EXE\" http://www..com");

熱點內容
c語言16進製表示方法 發布:2025-05-17 13:11:25 瀏覽:479
ftp單位 發布:2025-05-17 13:10:03 瀏覽:141
c語言編寫n的階乘 發布:2025-05-17 13:10:02 瀏覽:683
lockjava 發布:2025-05-17 13:02:08 瀏覽:310
只狼和看門狗哪個配置高 發布:2025-05-17 12:50:21 瀏覽:205
扁桃玩的伺服器地址 發布:2025-05-17 12:18:25 瀏覽:511
u盤上傳歌 發布:2025-05-17 12:14:51 瀏覽:615
入門c語言設計 發布:2025-05-17 12:08:31 瀏覽:41
c3演算法 發布:2025-05-17 12:04:19 瀏覽:365
phprecv 發布:2025-05-17 11:55:00 瀏覽:616