[REL] [ITA] Extr. informations from Libreria.Universitaria
Posted: 2009-09-19 05:48:36
Ecco: (Here you are:)
Bye 
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=
Title=Libreria Universitaria.IT.ifs
Description=
Site=
Language=IT
Version=
Requires=3.5.1
Comments=
License=
GetInfo=1
[Options]
***************************************************)
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=
Title=Libreria Universitaria
Description=
Site=
Language=?
Version=
Requires=3.5.0
Comments=
License=
GetInfo=0
[Options]
***************************************************)
program libri;
uses
StringUtils1;
var
MovieName: string;
TheMovieAddress: string;
UrlSearch, InitSearch, EndSearch: string;
comm: String;
const
crlf = #13#10; // carriage return/line feed
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr: integer;
BeginPos: integer;
begin
Page := TStringList.Create;
//ex Page.Text := GetPage(Address);
Page.Text := GetPage(Address);
SetField(fieldURL, Address);
LineNr := FindLine('class="small_font">Risultati per la tua ricerca', Page, 0);
if LineNr = -1 then
begin
SetField(fieldURL, Address);
AnalyzeMoviePage(Page);
end
else
begin
PickTreeClear;
AddMoviesTitles(Page);
if TheMovieAddress='' then
begin
if PickTreeExec(Address) then AnalyzePage(Address);
end
else
begin
SetField(fieldURL, MovieAddress);
Page.Text := GetPage(Address); //Page.Text := GetPage(TheMovieAddress);
AnalyzeMoviePage(Page);
end;
end;
Page.Free;
end;
procedure AnalyzeMoviePage(Page: TStringList); //estrae campi dalla pagina del libro scelto
var
SaveLine, Line, Value, PreviousLine, NomeHtml, sTemp: string;
LineNr,PrevLineNr, BeginPos, EndPos, Field: Integer;
BeginChar, EndChar: string;
SaveCommento, Commento: string;
BeginLineNr, endLineNr: Integer;
begin
// Picture import <table width="100%" cellpadding="8" border="0">
LineNr := FindLine('<table width="100%" cellpadding="8" border="0">', Page, 0);
Line := Page.GetString(LineNr);
Line := TextBetween(Line, 'src="', '" height="240"'); // Extract the picture URL from "Page"
if Line <> '' then // If "Value" now contains picture URL then..
GetPicture(Line); // .. download and save picture
LineNr := FindLine('<h3 class="product_section_title">Descrizione</h3>', Page, 0); // param. 1
if LineNr <> -1 then
begin
// LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
saveLine := Line;
// setfield(FieldComments, Line); // cancellare poi
Line := TextBetween(Line, '<div class="product_text" >', '</div>'); //trama param. 2
HTMLRemoveTags(Line);
HTMLDecode(Line);
Line := Fulltrim(Line);
setfield(FieldDescription, Line);
Line := SaveLine;
Line := TextBetween(Line, '<span class="product_label">Traduttore:</span>', '</span>'); // estrae Traduttore param. 3
HTMLRemoveTags(Line);
HTMLDecode(Line);
Line := Fulltrim(Line);
if Length(Line) > 0 then
begin
Line := 'Traduttore: ' + Line;
setfield(FieldActors, Line);
end
Line := SaveLine;
Line := TextBetween(Line, '<span class="product_label">Editore:</span>', '</span>'); // estrae Editore param. 3
HTMLRemoveTags(Line);
HTMLDecode(Line);
Line := Fulltrim(Line);
if Length(Line) > 0 then
begin
Line := 'Editore: ' + Line;
setfield(FieldProducer, Line);
end
Line := SaveLine;
Line := TextBetween(Line, '<span class="product_label">Data di Pubblicazione:</span>', '</span>'); // estrae Pubblicazione
HTMLRemoveTags(Line);
HTMLDecode(Line);
Line := Fulltrim(Line);
if Length(Line) > 0 then
begin
setfield(FieldYear, Line);
end
Line := SaveLine;
Line := TextBetween(Line, '<span class="product_label">Collana:</span>', '</span>'); // estrae Collana param. 3
Line := TextBetween(Line, 'title="', '"'); // estrae Collana param. 3
HTMLRemoveTags(Line);
HTMLDecode(Line);
Line := Fulltrim(Line);
if Length(Line) > 0 then
begin
Line := 'Collana: ' + Line;
setfield(Fieldcategory, Line);
end
Line := SaveLine;
Line := TextBetween(Line, '<span class="product_label">ISBN:</span>', '</span>'); // estrae ISBN
HTMLRemoveTags(Line);
HTMLDecode(Line);
Line := Fulltrim(Line);
if Length(Line) > 0 then
begin
Line := 'ISBN: ' + Line;
setfield(FieldVideoFormat, Line);
end
Line := SaveLine;
Line := TextBetween(Line, '<span class="product_label">ISBN-13:</span>', '</span>'); // estraeISBN13
HTMLRemoveTags(Line);
HTMLDecode(Line);
Line := Fulltrim(Line);
if Length(Line) > 0 then
begin
Line := 'ISBN13: ' + Line;
setfield(FieldAudioFormat, Line);
end
Line := SaveLine;
Line := TextBetween(Line, '<span class="product_label">Pagine:</span>', '</span>'); // estrae n.pagine
HTMLRemoveTags(Line);
HTMLDecode(Line);
Line := Fulltrim(Line);
setfield(FieldLength, Line);
Line := SaveLine;
Line := TextBetween(Line, '<span class="product_label">Titolo:</span>', '</span>'); // estrae Titolo param. 4
HTMLRemoveTags(Line);
HTMLDecode(Line);
Line := Fulltrim(Line);
setfield(FieldTranslatedTitle, Line);
LineNr := FindLine('<h2 class="product_text"', Page, 0);
Line := Page.GetString(LineNr);
Line := TextBetween(Line, 'title="', '"'); // estrae Autore
HTMLRemoveTags(Line);
HTMLDecode(Line);
Line := Fulltrim(Line);
setfield(FieldDirector, Line);
LineNr := FindLine('<br /><table border=0 cellspacing="12">', Page, 0); // inizio estrazione commenti
Line := Page.GetString(LineNr);
Line := TextBetween(Line, 'title="', '"'); // estrae Autore
HTMLRemoveTags(Line);
HTMLDecode(Line);
Line := Fulltrim(Line);
setfield(FieldDirector, Line);
//********************************* inizio aggiunta relativa ai commenti ******************************
BeginLineNr := FindLine('<br /><table border=0 cellspacing="12">', Page, 0); // inizio estrazione commenti
EndLineNr := FindLine('</table>', Page, BeginLinenr); // fine estrazione commenti
Line := '';
While BeginLineNr <= EndLineNr do
begin
Line := Line + Page.GetString(BeginLineNr); // inizio estrazione commenti
beginLineNr := BeginLineNr + 1;
end;
SaveCommento := '';
Commento := '*';
While Commento <> '' do
begin
BeginChar := 'border="0" > <b>';
EndChar := '<br />';
Commento := TextBetween(Line, BeginChar, EndChar); // estrae commento succinto
Commento := Commento + EndChar;
EndPos := Pos(Line, EndChar);
delete(line, 0, EndPos);
HTMLRemoveTags(Commento);
HTMLDecode(Commento);
// Commento := Fulltrim(Commento);
SaveCommento := SaveCommento + Commento + ' ';
BeginChar := '<br />';
EndChar := '<b>';
Commento := TextBetween(Line, BeginChar, EndChar); // estrae autore del commento;
Commento := Commento + EndChar;
EndPos := Pos(Line, EndChar);
delete(line, 0, EndPos);
HTMLRemoveTags(Commento);
HTMLDecode(Commento);
// Commento := Fulltrim(Commento);
SaveCommento := SaveCommento + Commento + ' - ';
BeginChar := 'leggi tutte le sue recensioni</a><br /><br /><font color="#67b00e">'; // estrae commento esteso
EndChar := '<font color=';
Commento := TextBetween(Line, BeginChar, EndChar); // estrae commento succinto
EndPos := Pos(Line, EndChar) + length(EndChar);
delete(line, 0, EndPos);
HTMLRemoveTags(Commento);
HTMLDecode(Commento);
Commento := Fulltrim(Commento);
SaveCommento := SaveCommento + Commento + crlf;
end;
setfield(FieldComments, SaveCommento);
//**************************************** aggiunta relativa ai commenti ******************************
end;
end;
procedure AddMoviesTitles(Page: TStringList);
var
LineNr: Integer;
Line: string;
MovieTitle, MovieAddress, Editor, year, MovieAuthor, Newmovietitle: string;
BeginChar: string;
BeginPos, EndPos: Integer;
begin
TheMovieAddress := '*';
LineNr := 0;
LineNr := FindLine('<table width="100%" border="0" cellpadding="5" cellspacing="2" align="center"', page, 0);
LineNr := FindLine('<td rowspan="3" width="5%" align="center" valign="top" >', page, LineNr);
while LineNr <> -1 do
begin
Line := Page.GetString(LineNr); // riga dell'URL
BeginChar := '<a href="';
MovieAddress := Textbetween(Line, BeginChar, '"'); // link del libro
EndPos := pos(BeginChar, Line) + length(MovieAddress) + 1;
HTMLRemoveTags(MovieAddress);
HTMLDecode(MovieAddress);
MovieAddress := FullTrim(MovieAddress);
TheMovieAddress := MovieAddress;
Line := TextAfter(Line, Beginchar);
BeginChar := 'title="';
MovieTitle := Textbetween(Line, BeginChar, '"'); // titolo del libro
HTMLRemoveTags(MovieTitle);
HTMLDecode(MovieTitle);
MovieTitle := FullTrim(MovieTitle);
LineNr := LineNr + 1;
Line := Page.GetString(LineNr); // riga del titolo, autore, editore
BeginChar := 'title="';
MovieAuthor := Textbetween(Line, BeginChar, '"'); // salta campo titolo libro
EndPos := pos(BeginChar, Line) + length(BeginChar) + length(MovieAuthor) + 1;
delete(line, 1, EndPos);
BeginChar := 'title="';
MovieAuthor := Textbetween(Line, BeginChar, '"'); // Editore
EndPos := pos(BeginChar, Line) + length(BeginChar) + length(MovieAuthor) + 1;
delete(line, 1, EndPos);
MovieTitle := MovieTitle + ' (' + MovieAuthor + ' - ';
BeginChar := 'title="';
MovieAuthor := Textbetween(Line, BeginChar, '"'); // Autore
EndPos := pos(BeginChar, Line) + length(BeginChar) + length(MovieAuthor) + 1;
MovieTitle := MovieTitle + MovieAuthor + ')';
PickTreeAdd(Movietitle, MovieAddress);
TheMovieAddress := '*';
LineNr := LineNr + 1;
LineNr := FindLine('<td rowspan="3" width="5%" align="center" valign="top" >', page, LineNr);
end;
if TheMovieAddress='*' then TheMovieAddress := '';
end;
// -----------------------------
// Questo è il main dello script
// -----------------------------
begin
if CheckVersion(3,5,0) then
begin
MovieName := StringReplace(GetField(fieldTranslatedTitle), ' ', '+');
if MovieName = '' then
MovieName := StringReplace(GetField(fieldOriginalTitle), ' ', '+');
if Input('LibreriaUniversitaria Import', 'Digita il titolo del libro:', MovieName) then
begin
// AnalyzePage('http://www.libreriauniversitaria.it/c_search.php?noinput=1&shelf=BIT&title_query='+UrlEncode(MovieName)+'&author_query=&publisher_query=&series_query=&subject_query=&isbn_query=&dewey_query=AAA&search=Cerca');
InitSearch := 'http://www.libreriauniversitaria.it/c_advanced_search.php?query=1&query_shelf=BIT&query_title=' + MovieName;
EndSearch := '&query_author=&query_publisher=&query_series=&query_abstract=&query_code=&query_category=AAA&query_availability=ALL&query_date_range=bef&query_date=2009&query_order_by=DEF&search=Cerca';
UrlSearch := InitSearch + EndSearch;
// SetField(fieldURL, UrlSearch); //URL della ricerca
AnalyzePage(UrlSearch);
end;
end
else
ShowMessage('Questo script richiede una versione più nuova di Ant Movie Catalog (almeno la versione 3.5.0)');
end.
