v2.5.2
Giriş yap

Türsab PHP botu

Anonim
1,779 defa görüntülendi ve 2 kişi tarafından değerlendirildi

Türsab tasarımını değiştirmiş, eskiden botum vardı ancak artık çalışmıyor. Yani halinden veri çekebileceğimiz bir kod parçası var mıdır elinizde?

tayfunerbilen
1634 gün önce

Son tasarımından veri çekmek için bir class yazdım;

/**
 * Class Tursab
 * @author Tayfun Erbilen
 */
class Tursab
{

	public $no;
	public $output;
	public $data;

	public function __construct($no)
	{
		$this->no = $no;
		$this->getSource();
	}

	public function getSource()
	{
		$this->curl('https://online.tursab.org.tr/publicpages/embedded/agencysearch/');

		preg_match_all('@PublicKeyToken%3d(.*?)%@', $this->output, $publicKeyToken);
		preg_match('@id="__VIEWSTATE" value="(.*?)"@', $this->output, $viewState);
		preg_match('@id="__VIEWSTATEGENERATOR" value="(.*?)"@', $this->output, $viewStateGenerator);
		preg_match('@id="__EVENTVALIDATION" value="(.*?)"@', $this->output, $eventValidation);

		$postData = [];
		$postData['ctl00$RadScriptManager'] = 'ctl00$ContentPlaceHolder1$UpdatePanel1|ctl00$ContentPlaceHolder1$SearchButton';
		$postData['RadScriptManager_TSM'] = ';;System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=' . $publicKeyToken[1][0] . ':en-US:22727c22-244c-4537-8243-3c42cc5b20e2:ea597d4b:b25378d2;AjaxControlToolkit, Version=18.1.1.0, Culture=neutral, PublicKeyToken=' . $publicKeyToken[1][1] . ':en-US:b13aac2d-1c5e-49ed-8aa2-800cbed84558:cd9be5ef:f2800037:2761bb61:10439726:98f9cc63:dffb332:dda46be5:78181a00:f4e67d46;';
		$postData['__EVENTTARGET'] = '';
		$postData['__EVENTARGUMENT'] = '';
		$postData['ctl00$ContentPlaceHolder1$TursabNo$AutoCompleteTextBox'] = '';
		$postData['ctl00$ContentPlaceHolder1$TursabNo$AutoCompleteTextBoxHF'] = '';
		$postData['ctl00$ContentPlaceHolder1$TursabNo$AutoCompleteTextBoxTF'] = '';
		$postData['ctl00$ContentPlaceHolder1$TursabNoText'] = $this->no;
		$postData['hiddenInputToUpdateATBuffer_CommonToolkitScripts'] = '1';
		$postData['__VIEWSTATE'] = $viewState[1];
		$postData['__VIEWSTATEGENERATOR'] = $viewStateGenerator[1];
		$postData['__EVENTVALIDATION'] = $eventValidation[1];
		$postData['__ASYNCPOST'] = true;
		$postData['ctl00$ContentPlaceHolder1$SearchButton'] = 'ARA';

		$this->curl('https://online.tursab.org.tr/publicpages/embedded/agencysearch/', $postData);
		preg_match_all('@<div class="litc"><span style="color:red;">Acenta Adı : </span>(.*?)</div>@', $this->output, $agentName);
		preg_match_all('@<div class="litc"><span style="color:red;">Telefon : </span>+(.*?)<br />@', $this->output, $agentPhone);
		preg_match_all('@<div class="litc"><span style="color:red;">Email : </span>+(.*?)</div>@', $this->output, $agentMail);
		preg_match_all('@<span class="red-label">Adres : </span>(.*?) <b>.*?</b> / <b>.*?</b>@', $this->output, $agentAddress);

		if (isset($agentName[1]) && isset($agentPhone[1]) && isset($agentAddress[1])) {

			$agents = [];
			foreach ($agentName[1] as $key => $val) {
				preg_match_all('@<b>(.*?)</b>@', $agentAddress[0][$key], $cityState);
				$agents[] = [
					'no' => $this->no,
					'name' => $val,
					'city' => $cityState[1][1],
					'state' => $cityState[1][0],
					'address' => $agentAddress[1][$key],
					'phone' => $agentPhone[1][$key],
					'mail' => $agentMail[1][$key]
				];
			}

			$this->data = $agents;
		}

	}

	public function curl($url, $post = false)
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_REFERER, $url);
		curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
		curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		if ($post) {
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
		}
		$output = curl_exec($ch);
		curl_close($ch);
		$this->output = str_replace(["\n", "\r", "\t"], null, $output);
	}

	public function getData()
	{
		return $this->data;
	}

}

$tursab = new Tursab(7089);
print_r($tursab->getData());