Raised This Month: $12 Target: $400
 3% 

Problem with read content of the web


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Solutioned
Junior Member
Join Date: Mar 2008
Old 10-18-2009 , 00:45   Problem with read content of the web
Reply With Quote #1

¿How can I read all content of the web? because the web will change everyday and I want to save the content into a file.

Here is my code:
Code:
#include <amxmodx>
#include <sockets>

new const CGT_VERSION[] = "1.00"
new const CGT_HOST[] = "www.cgtworld.com"
new gSocket
new updated = 0

public plugin_init() {
	register_plugin("CGT Match Info", CGT_VERSION, "CGT Dev Team")
	register_cvar("cgt_version", CGT_VERSION, FCVAR_SERVER)
	register_srvcmd("cgt_update", "update")
	set_task(3600.0,"update")
	update()
	//register_event("HLTV", "update", "a")
}

public update() {
	server_print("Actualizando...")
	if(!updated) {
		new socket_error = 0
		gSocket = socket_open(CGT_BL_HOST, 80, SOCKET_TCP, socket_error)
		if(socket_error != 0) {
			switch (socket_error)
			{
				case 1:
					server_print("Error en crear conexion")
				case 2:
					server_print("Error en resolver el nombre del servidor")
				case 3:
					server_print("Error en intentar a conectarse")
			}
			return PLUGIN_CONTINUE
		}
		new send[256]
		formatex(send, 255, "GET /match/id-1/info.txt HTTP/1.1^r^nHost: %s^r^nConnection: close^r^n^r^n", CGT_HOST)
		socket_send(gSocket, send, strlen(send))
		if(!task_exists(5048)) set_task(0.25, "write_cgt", 5048, _, _, "b")
	} else server_print("CGT ya ha sido actualizado recientemente")
	return PLUGIN_CONTINUE
}

public write_cgt() {
	new head[174]
	if(socket_change(gSocket)) {
		socket_recv(gSocket, head, 173)
		new lines[7][174]
		ExplodeString(lines, 50, 119, head, 13)
		new value[10]
		new variable[30]
		parse(lines[6], variable, 29, value, 9)
		new const rSize = str_to_num(value)
		new receive[1024]
		socket_recv(gSocket, receive, 1023)
		new info
		info = fopen("info.dat", "a")
		fprintf(info, receive)
		fclose(info)
		updated = 1
		remove_task(5048)
		socket_close(gSocket)
		server_print("CGT ha sido actualizado correctamente")
	}
}

stock ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter ) { // Function by xeroblood
    new nIdx = 0, l = strlen(p_szInput)
    new nLen = (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput, p_szDelimiter ))
    while( (nLen < l) && (++nIdx < p_nMax) )
        nLen += (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput[nLen], p_szDelimiter ))
    return nIdx
}
Thanks!
Solutioned is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 10-18-2009 , 13:15   Re: Problem with read content of the web
Reply With Quote #2

I am converting cURL to an Amxx Module
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
Solutioned
Junior Member
Join Date: Mar 2008
Old 10-18-2009 , 13:52   Re: Problem with read content of the web
Reply With Quote #3

xD, I only want get all body of the webpage, without header, but I can not found a function that like PHP substr function in AMXX.

Are someone can help me?
Solutioned is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 10-18-2009 , 14:21   Re: Problem with read content of the web
Reply With Quote #4

Quote:
Originally Posted by Solutioned View Post
xD, I only want get all body of the webpage, without header, but I can not found a function that like PHP substr function in AMXX.

Are someone can help me?
You can play with split, parse and strbreak functions.
They're not like substr but may help.

With split function you can get a substring in the middle.
You always need to know the lenght of the string.

Remember you can make your own substr stock with this functions.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:57.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode