#!/usr/bin/perl
$time1=time;
$oqsl=$oqs{'Biblion'};
# Whole string
$ttok1="ru/books/product.asp";
$ttok2="Цена";
# Item Name
$ttok3="\">\t\t";
$ttok4="
";
$ttok15="Авторы: ";
$ttok6="
Изд";
# Item Price
$ttok7="Цена: ";
$ttok8="р.";
# Item Reference
$ttok9="/books/product.asp?sku=";
$ttok10="\&super=";
$ttok14="Цена ";
# Item delivery conditions
# $ttok11="Наличие: ";
# $ttok12="";
# Token to skip record
# $ttok13="Оставить заявку";
$itempic="/images/blank_cover.gif";
$pushline=0;
$lpath=$oq{'Biblion'};
$shop="Biblion";
undef @output;
# &IOsocket;
$resultio=IOsocket();
### Debig zone
# open (file,">../../write/testbiblion.txt");
#
# foreach $out (@output) {
# printf (file "$out");
# };
#
# close (file);
# open (file,">../../write1/test2.txt");
#
# printf (file "$buff\n");
#
# close (file);
$inside=0;
$readytoprocess=0;
$pstring="";
$olen=$#output +1;
plog("Biblion answer has - $olen lines");
if($olen) {
foreach $outline (@output) {
if ($outline =~ /$ttok1/) { $inside=1;};
if ($inside == 1) {
$pstring.=$outline;
$pstring=~ s/\n//g;
$pstring=~ s/\r//g;
# print ("\n");
};
if (($inside == 1) && ($outline =~ /$ttok2/)) {
$inside=0;
$readytoprocess=1;
#print "\n\n\n";
};
if ($readytoprocess == 1) {
# $pstring.="\n";
# $pstring=~ s/ NEW!<\/B><\/I>//g;
# $pstring=~ s///;
# $pstring=~ s/<\/B>//;
$ltk=$ttok3;
$rtk=$ttok4;
$p1=index($pstring,$ltk)+length($ltk);
$p2=index($pstring,$rtk)-$p1;
$itemname=substr($pstring,$p1,$p2);
#print "\n";
if($pstring=~ /$ttok5/) {
$ltk=$ttok5;
} else {
$ltk=$ttok15;
};
$rtk=$ttok6;
$p1=index($pstring,$ltk)+length($ltk);
$p2=index($pstring,$rtk)-$p1;
$itemauthor=substr $pstring,$p1,$p2;
$itemauthor=~ s/
/ /;
if(index($pstring,$ltk) < 0) {
$itemauthor="В результатах поиска не указан.";
};
$itemauthor =~ s/<([^>]|\n)*>//g;
#print "\n";
$ltk=$ttok7;
$rtk=$ttok8;
$p1=index($pstring,$ltk)+length($ltk);
$p2=index($pstring,$rtk)-$p1;
$itemprice=substr $pstring,$p1,$p2;
$itemprice=~ s/,/./;
if($itemprice=~ /$ttok14/go) {
$itemprice=" Будет сообщена по Вашему запросу";
};
#print "\n";
$ltk=$ttok9;
$rtk=$ttok10;
$p1=index($pstring,$ltk)+length($ltk);
$p2=index($pstring,$rtk)-$p1;
$itemref=substr $pstring,$p1,$p2;
$itemref="http://www.biblion.ru/books/buynow/default.asp?pid=".$prtid."\&sku=".$itemref;
#print "\n";
# $ltk=$ttok11;
# $rtk=$ttok12;
# $p1=index($pstring,$ltk)+length($ltk);
# $p2=index($pstring,$rtk)-$p1;
# $itemdelivery=substr $pstring,$p1,$p2;
$itemdelivery="В результатах поиска не указана. Смотри описание товара.";
#print "\n";
# if ($pstring =~ /$ttok13/go) {
# $itemname="";
# $itemauthor="";
# $itemprice="";
# $itemref="";
# $itemdelivery="";
# };
$badtok1=">";
$badtok2="<";
if(($itemname =~ /$badtok1/) || ($itemname =~ /$badtok2/)) {
push(@showline,"***! Обработка страницы прервана. Неопознанный формат. ***\n");
print "\n";
last;
};
if(($itemauthor =~ /$badtok1/) || ($itemauthor =~ /$badtok2/)) {
push(@showline,"***! Обработка страницы прервана. Неопознанный формат. ***\n");
print "\n";
last;
};
if(($itemprice =~ /$badtok1/) || ($itemprice =~ /$badtok2/)) {
push(@showline,"***! Обработка страницы прервана. Неопознанный формат. ***\n");
print "\n";
last;
};
if(($itemref =~ /$badtok1/) || ($itemref =~ /$badtok2/)) {
push(@showline,"***! Обработка страницы прервана. Неопознанный формат. ***\n");
print "\n";
last;
};
if(($itemdelivery =~ /$badtok1/) || ($itemdelivery =~ /$badtok2/)) {
push(@showline,"***! Обработка страницы прервана. Неопознанный формат. ***\n");
print "\n";
last;
};
$lists++;
if ($itemname ne "") {
if (index($itemprice,".") < 0) { $itemprice=$itemprice.".";};
if (index($itemprice,".") == 1) { $itemprice=" ".$itemprice;};
if (index($itemprice,".") == 2) { $itemprice=" ".$itemprice;};
if (index($itemprice,".") == 3) { $itemprice=" ".$itemprice;};
if (index($itemprice,".") == 4) { $itemprice=" ".$itemprice;};
if (index($itemprice,".") == 5) { $itemprice=" ".$itemprice;};
if (index($itemprice,".") == 6) { $itemprice=" ".$itemprice;};
# push(@showline,"Название: $itemname
Автор: $itemauthor
Цена: $itemprice
Доставка: $itemdelivery
\n");
push(@showline2,"$itemprice ||$itemname||$itemauthor||$itemref||$itemdelivery||$shop||$oqsl\&ptr=$prtid||$itempic\n");
};
$pstring="";
$readytoprocess=0;
};
};
};
print "";
$time2=time;
1;