-
Notifications
You must be signed in to change notification settings - Fork 1
/
Temp_Aust.php
73 lines (53 loc) · 1.72 KB
/
Temp_Aust.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/*
Project: Australia_Scraping
*/
const cookiefile = 'cookie.txt';
const POST = true;
const GET = false;
$pattern = '@_token"\svalue="(.+?)"@';
$url = "https://www.businesses2sell.com.au/australia/act";
$data = get_source($url, GET);
$token = get_words($pattern, $data);
$post = [
'_token' => $token,
'iteration' => '2', // for this time
'feed' => 'search',
'state' => 'ACT',
'region' => '',
'city' => '',
'category' => '',
'pricing' => '',
];
$data = get_source('https://www.businesses2sell.com.au/data/fetch', POST, $post);
echo $data;
# FUNCTIONALITY START HERE
function get_words($pattern, $string){
preg_match($pattern, $string, $match);
if( isset($match[1]) ) {
return $match[1];
}
else{
return false;
}
}
function get_source($url, $method, $fields = null){
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_COOKIEFILE, cookiefile);
curl_setopt($handle, CURLOPT_COOKIEJAR, cookiefile);
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
if($method == true){
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_HTTPGET, false);
curl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($fields));
$source = curl_exec($handle);
}else{
curl_setopt($handle, CURLOPT_HTTPGET, true);
curl_setopt($handle, CURLOPT_POST, false);
}
$source = curl_exec($handle);
curl_close($handle);
return $source;
}