¿Conocéis harkerrrank? 
https://www.hackerrank.com/
Si no lo conocéis deberíais, puede ser interesante para practicar.

https://www.hackerrank.com/
Si no lo conocéis deberíais, puede ser interesante para practicar.

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú$('td').css('display', 'none')
de jQuery y eso lo que hace es cambiar el css de los elementos en el html, con el atributo style, no cambiar las reglas css.if __name__=="__main__":
códigoo que se ejecuta sólo al llamar a este fichero pero no al hacer include
if (debug_backtrace()){
//ejecutar si include;
} else {
//ejecutar si no include
}
class PHPBot {
function PHPBot (){
$this->ch = curl_init();
$ch = $this->ch;
curl_setopt($ch, CURLOPT_HEADER, 1); // Include headers in response or not
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return (don't print) answer of exec
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12");
curl_setopt($ch, CURLOPT_AUTOREFERER, true); // Isn't this great?
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: */*', 'Accept-Language: en-us,en;q=0.5', 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7'));
}
private function act($url, $params = false){
$ch = $this->ch;
curl_setopt($ch, CURLOPT_URL, $url);
if ($params != false){
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->myurlencode($params));
curl_setopt($ch, CURLOPT_POST, 1);
}
else
curl_setopt($ch, CURLOPT_POST, 0);
$r = curl_exec($ch);
return $r;
}
private function myurlencode($dict){
$r = "";
foreach($dict as $key => $value)
$r = $r.urlencode($key).'='.urlencode($value).'&';
return $r;
}
function get ($url){
return $this->act($url);
}
function post($url, $params){
return $this->act($url, $params);
}
}
Cita de: lnvisible en 16 Septiembre 2011, 00:32 AM
Y lo que yo digo es que si entre todos juntamos un poquito que aporte cada uno lo podemos hacer mucho mejor.
Por ejemplo, lo que has hecho madpitbull quedaría así:<?php
class PHPBot {
private $ch;
function __construct() {
$this->ch = curl_init();
curl_setopt ($this->ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($this->ch, CURLOPT_RETURNTRANSFER, 1);
}
public function getURL(url, args) {
curl_setopt($this->ch, CURLOPT_URL, url);
if (args){
curl_setopt ($this->ch, CURLOPT_POSTFIELDS, funcionquenoexistetodavia(args);
curl_setopt ($this->ch, CURLOPT_POST, 1);
}
return curl_exec($this->ch);
}
function __destruct() {
curl_close ($this->ch);
}
}
?>
Pero para hacer un buen bot todavía queda mucho.
También intuyo que habrá mejores formas que curl, no parece estándar de php.
import http.client, urllib.parse
from http import cookies
from re import findall
class CrawlerGeneral ():
def __init__(self):
self.logininfo = []
self.baseheaders = {"User-Agent":"Mozilla/5.0 (Windows; en-US; XP) Gecko/20101028 Firefox/3.5.15",
"Accept": "*/*", "Accept-Language":"en-us,en;q=0.5",
"Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7"}
self.cookies = cookies.SimpleCookie()
self.referer = ''
def _act(self, url, method, params={}):
headers = self.baseheaders.copy()
headers['Referer'] = self.referer
headers['Cookie'] = self.cookies.output(header='', sep=';')
self.referer = url
if(url[:7] == 'htt'+'p://'):
url = url[7:]
safe = False
elif (url[:8] == 'htt'+'ps://'):
url = url[8:]
safe = True
else:
self.error("I don't like the protocol, I don't know how to handle this.\n" + url)
(baseurl, extendedurl) = url.split('/', 1)
extendedurl = '/' + extendedurl
params = urllib.parse.urlencode(params)
conn = http.client.HTTPConnection(baseurl) if not safe else http.client.HTTPSConnection(baseurl)
conn.request(method, extendedurl, params, headers)
resp = conn.getresponse()
return self._processResponse(resp)
def _processResponse(self, resp):
data = resp.read()
headers = resp.getheaders()
data = bytes.decode(data)
for (k, v) in headers:
if k == 'Set-Cookie':
self.cookies.load(v)
return (headers, data)
def post(self, url, params):
realparams = urllib.parse.urlencode(params)
return self._act(url, 'POST', params)
def get(self, url):
return self._act(url, 'GET')
from crawlergeneral import CrawlerGeneral
from re import findall
cg = CrawlerGeneral()
(headers, data) = cg.get('htt'+'p://foros.solocodigo.com/ucp.php?mode=login')
sid = findall('type="hidden" name=%2526quot%253Bsid%2526quot%253B value="([^"]+)"', data)[0]
(headers, data) = cg.post('htt'+'p://foros.solocodigo.com/ucp.php?mode=login', {'username' : 'Invisible', 'password': 'password', 'sid':sid, 'redirect': 'index.php', 'login':'Identificarse'})
print(data)
CitarNo se puede establecer una conexión de datos fiable con el servidor.
Es posible que se trate de un problema temporal o que no se proporcione la tarjeta SIM para servicios de datos. Si el problema persiste, llama al servicio de atención al cliente.
headers = {"User-Agent":"Mozilla/5.0 (Windows; en-US; XP) Gecko/20101028 Firefox/3.5.15", "Accept": "*/*", "Accept-Language":"en-us,en;q=0.5", "Accept-Encoding": "gzip,deflate", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7"}
import http.client
conn = http.client.HTTPConnection("foro.elhacker.net")
conn.request("GET", "/", None, headers)
pr = conn.getresponse()
pr.getheaders()
content = pr.read()
import zlib
def write(f, t):
with open(f, 'w') as o:
o.write(t)