-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbonds-search.php
48 lines (41 loc) · 1.48 KB
/
bonds-search.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
<?php
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
set_time_limit(0);
error_reporting(E_ALL);
header('Content-type: text/html; charset=utf-8');
require_once 'simple_html_dom.php';
$dblocation = "localhost";
$dbname = "bonds";
$dbuser = "root";
$dbpasswd = "";
$dbcnx = mysql_connect($dblocation,$dbuser,$dbpasswd);
if (!$dbcnx) exit('DB failure');
if (!@mysql_select_db($dbname,$dbcnx)) exit('DB failure');
mysql_query ("set collation_connection='utf8_general_ci'");
define('BASE_URL', 'http://rusbonds.ru');
$epog = date('d.m.Y', strtotime('today + 1 year'));
$search_page = '/srch_simple.asp?go=1&sec=6&status=T&pvt=2&blof=on&epog='.$epog;
if (!isset($_GET['pages'])) {
exit('Go to <a target="_blank" href="'.BASE_URL . $search_page.'">search</a> and specify number of result pages via $_GET[pages]');
}
$results = array();
$pages = $_GET['pages'];
mysql_query("TRUNCATE tbl_search_results");
//$pages = 1; // tmp
for ($i = 1; $i <= $pages; $i++) {
$search = file_get_html(BASE_URL . $search_page . '&p=' . $i);
$j = 1;
foreach ($search->find('.tbl_data tbody tr td a') as $result) { // this selector works bad
if ($j <= 9) {
$j++;
continue;
}
$name = $result->plaintext;
$link = BASE_URL . $result->href;
mysql_query("INSERT INTO tbl_search_results (name, link) VALUES ('$name', '$link')");
}
}
// assume we always have >9 pages of results
//preg_match_all('/<a href=\/([\S]{1,}) class=bl>\d+\.\.\.\d+<\/a>/', 'test', $pagination_matches);