Reply about the Scraping Example Test code.

This post is a reply to the shinokada's question.

Creating an object from a class in Codeigniter -
http://stackoverflow.com/questions/1513685/creating-an-object-from-a-class-in-codeigniter/


CodeIgniter study 14 (In Japanese text) -
http://d.hatena.ne.jp/dix3/20081002/1222899116

In English text (Google Translator) -
http://translate.google.com/translate?prev=hp&hl=en&js=y&u=http%3A%2F%2Fd.hatena.ne.jp%2Fdix3%2F20081002%2F1222899116&sl=ja&tl=en)

I've tried to post again. but I couldn't post with hyperlinks. sorry.. I'll answer to that in this site.(I'm a newbie stackoverflow.com :-( )


I think that I'll try to repost these answers after a few days .(on stackoverflow.com)


Answer

Hi! . This sample Scraping code was written based on using the library:
Snoopy - the PHP net client ( http://snoopy.sourceforge.net/ )

Mistakes in my English ,please pardon me : )


Q1. Am I correct to say that I can't use,

A1.

You have to install this source code:

  • step1: Download the base source(Snoopy-1.2.4.zip) at http://sourceforge.net/projects/snoopy/
  • step2: Unzip Snoopy-1.2.4
  • step3: Rename Snoopy.class.php to Snoopy.php (My sample Scraping libraly name is not 'Snoopy.php', 'Scraping.php' is correct)
  • step4: Move Snoopy.php(which was renamed) to application/libraries/Snoopy.php
  • step5: Install my sample wrapper code(class Scraping) to application/libraries/Scraping.php


Note1:
Required php-curl environment, I dont know how to install it on XAMPP.
This site may help you - http://stackoverflow.com/questions/176449/how-to-install-php-curl/ ,
Under the Linux OS, it's easy to install . (ex. yum install curl or apt-get install curl)


Note2:
If you want to try to use 'Snoopy class' only in HTTP ,Change the Snoopy.php at line 85. so Note1 is not required.

Snoopy.php (which was renamed) at line 85:

 #var $curl_path="/usr/local/bin/curl";
 var $curl_path=false;

Q2. Why do the author use

A2.

That's an "auto HtmlSpecialchars option".
Because the browser does not display the HTML tags.

(please see: http://www.php.net/manual/en/function.htmlspecialchars.php ).

Note3:
In the sample wrapper code, I use 'mb_convert_encoding' functions.
This php-function may not be installed on English environment.
(see: http://www.php.net/manual/en/function.mb-convert-encoding.php )

If you can't use this 'mb_ php-function' Change this. ..(or Install 'mb_' functions):

Scraping.php(my Snoopy Wrapper example code):

 #$str = mb_convert_encoding( (string) $this -> c -> results,"UTF-8","auto");
 $str = (string) $this -> c -> results ;


Q3. Could you explain APPPATH and EXT.

A3.

'APPPATH' and 'EXT' are Reserved Names(Constants) on CodeIgniter.

'APPPATH' - The full server path to the "system" folder. (ex. '/var/blah/blah/system/application/')

'EXT' - The file extension. Typically '.php'

(see:htdocs/index.php at line 88)
(see also: http://codeigniter.com/user_guide/general/reserved_names.html)




Regards. :-)