@@ -45,8 +45,8 @@ public static function get_more_results($html){
45
45
$ clean_html = $ purifier ->purify ($ html );
46
46
47
47
# Build a HTML parser to search for items.
48
- $ this -> dom = new Dom ;
49
- $ this -> dom ->load ($ clean_html );
48
+ $ dom = new Dom ;
49
+ $ dom ->load ($ clean_html );
50
50
51
51
# Get result items from the HTML.
52
52
$ items = $ dom ->find (".listing-item " );
@@ -125,7 +125,7 @@ private static function parse_items($items){
125
125
* This function also parse the initial result page and fetch additional
126
126
* pages to build the list of associated arrary for item information.
127
127
*/
128
- public function fetch (){
128
+ public function fetch ($ start_page = 2 ){
129
129
# Track time;
130
130
$ this ->time = time ();
131
131
@@ -145,16 +145,17 @@ public function fetch(){
145
145
146
146
$ num_results_on_page = count ($ items );
147
147
148
+
148
149
# Get the total number of pages.
149
- try {
150
- $ last_page_query = $ this -> dom -> find ( ' .paging_forward #last_page ' )-> getAttribute ( " href " );
151
- preg_match ( " /page=(\d+)/ " , $ last_page_query, $ num_pages_query );
152
- if ( isset ( $ num_pages_query [ 0 ][ 1 ])){
153
- $ this -> num_pages = intval ( explode ( " = " , $ num_pages_query [ 0 ])[ 1 ]);
154
- } else {
155
- $ this -> num_pages = 1 ;
156
- }
157
- }catch ( Exception $ e ) {
150
+ $ last_page_query = $ this -> dom -> find ( ' .paging_forward #last_page ' )-> getAttribute ( " href " );
151
+ if ( empty ( $ last_page_query)){
152
+ $ last_page_query = $ this -> dom -> find ( ' .paging_forward a ' )[ 1 ]-> getAttribute ( " href " );
153
+ }
154
+
155
+ preg_match ( " /page=(\d+)/ " , $ last_page_query , $ num_pages_query );
156
+ if ( isset ( $ num_pages_query [ 0 ][ 1 ])){
157
+ $ this -> num_pages = intval ( explode ( " = " , $ num_pages_query [ 0 ])[ 1 ]);
158
+ }else {
158
159
$ this ->num_pages = 1 ;
159
160
}
160
161
@@ -163,7 +164,6 @@ public function fetch(){
163
164
if ($ this ->num_results > $ this ->total_results || $ this ->num_results == "all " ){
164
165
$ this ->num_results = $ this ->total_results ;
165
166
}
166
-
167
167
if ($ num_results_on_page > 0 ){
168
168
$ page_needed = intval ($ this ->num_results / $ num_results_on_page );
169
169
}else {
@@ -172,8 +172,8 @@ public function fetch(){
172
172
173
173
$ page_urls = [];
174
174
$ base_url = preg_replace ("/page=(\d+)/ " , "" , $ last_page_query );
175
- for ($ i = 2 ; $ i <= $ page_needed ; $ i ++){
176
- array_push ($ page_urls , $ this ->url .$ base_url . "&page= $ i " );
175
+ for ($ i = $ start_page ; $ i <= $ page_needed && $ i <= $ this -> num_pages ; $ i ++){
176
+ array_push ($ page_urls , $ this ->url ."&page= $ i " );
177
177
}
178
178
179
179
# Fetch additional pages.
0 commit comments