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]='