Code : Tout sélectionner
#include <Array.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
HotKeySet("!q", "_Stop")
Global $stop
Local $array, $iRows, $iColumns, $iRval, $hQuery
_SQLite_Startup ()
_SQLite_Open(@ScriptDir & "\bouquins3.sqlite")
_SQLite_Exec (-1, "CREATE TABLE IF NOT EXISTS liste (EAN UNIQUE, image, titre, auteur, prix, description, editeur, Collection, Parution, Genre, 'Nombre de pages', Dimension, Poids);")
$txtcsv = "EAN|image|titre|auteur|prix|description|Editeur|Collection" & _
"|Parution|Genre|Nb. de pages|Dimensions|Poids" & @crlf
;~ local $FichierCsv = "Stock Librairie.csv"
;~ local $file = FileRead($FichierCsv)
local $file = "9782351555125" & @crlf & _
"9782266243216" & @crlf & _
"3782266243216"
$lines = StringRegExp($file, '(?m)(^.*)\R?', 3)
For $i = 0 to UBound($lines)-1
If $stop Then Exitloop
$txtcsv &=_Check($lines[$i]) & @crlf
Next
FileWrite("sortie stock.csv", $txtcsv)
_SQLite_GetTable2d (-1, "SELECT * FROM liste ORDER BY EAN DESC;", $array, $iRows, $iColumns)
_ArrayDisplay($array)
_SQLite_Close ()
_SQLite_Shutdown ()
;=================================================================
Func _Stop()
$stop = 1
EndFunc
Func _CleanTags($string)
Return StringRegExpReplace($string, '(?s)(\s*<.*?>\s*)', "")
EndFunc
Func _Check($isbn)
Local $source = BinaryToString(InetRead('http://www.placedeslibraires.fr/detaillivre.php?gencod=' & $isbn), 1)
If not StringInStr($source, 'link rel="alternate') Then Return $isbn & "|NO INFO"
$source = _HTML_StringToChars($source)
Local $res[13], $item
$item = StringRegExp($source, '(?s)class="visuRecto">\s*<img src="([^"]+)', 3)
If IsArray($item) Then $res[1] = $item[0]
$item = StringRegExp($source, '(?s)class="titre">\s*(.*?)\s*</h1', 3)
If IsArray($item) Then $res[2] = _CleanTags($item[0])
$item = StringRegExp($source, '(?s)class="auteur">\s*(.*?)\s*</h2', 3)
If IsArray($item) Then $res[3] = _CleanTags($item[0])
$item = StringRegExp($source, '(?s)class="editeur">\s*(.*?)\s*</a', 3)
If IsArray($item) Then $res[6] = _CleanTags($item[0])
$item = StringRegExp($source, '(?s)class="prix">.*?([\d.,]+)', 3)
If IsArray($item) Then $res[4] = _CleanTags($item[0])
$item = StringRegExp($source, '(?s)Collection :</label>\s*(.*?)</li>', 3)
If IsArray($item) Then $res[7] = _CleanTags($item[0])
$item = StringRegExp($source, '(?s)Parution :</label>\s*([^<]+)', 3)
If IsArray($item) Then $res[8] = $item[0]
$item = StringRegExp($source, '(?s)Genre :</label>\s*([^<]+)', 3)
If IsArray($item) Then $res[9] = $item[0]
$item = StringRegExp($source, '(?s)EAN :</label>\s*([^<]+)', 3)
If IsArray($item) Then $res[0] = $item[0]
$item = StringRegExp($source, '(?s)Nombre de pages :</label>\s*([^<]+)', 3)
If IsArray($item) Then $res[10] = $item[0]
$item = StringRegExp($source, '(?s)Dimension :</label>\s*([^<]+)', 3)
If IsArray($item) Then $res[11] = $item[0]
$item = StringRegExp($source, '(?s)Poids :</label>\s*([^<]+)', 3)
If IsArray($item) Then $res[12] = $item[0]
$item = StringRegExp($source, '(?s)class="bloc_presentation">([^<]+)', 3)
If IsArray($item) Then $res[5] = $item[0]
; _ArrayDisplay($res)
Local $values = "", $lignecsv = ""
For $i = 0 to UBound($res)-1
$values &= _SQLite_FastEscape($res[$i]) & ','
$lignecsv &= $res[$i] & "|"
Next
$values = StringTrimRight($values, 1)
$lignecsv = StringTrimRight($lignecsv, 1)
_SQLite_Exec(-1, "Begin;")
_SQLite_Exec(-1, "INSERT OR REPLACE INTO liste VALUES (" & $values & ");")
_SQLite_Exec(-1, "Commit;")
Return $lignecsv
EndFunc
Func _HTML_StringToChars($sString)
; merci matwachich
Local $__HTML_SpecialChars[131][3] = [ _
[130, "", ""], _
['"', '"', '"'], _
['&', '&', '&'], _
['€', '€', '€'], _
['', '', ''], _
['‚', '‚', ''], _
['ƒ', 'ƒ', ''], _
['„', '„', ''], _
['…', '…', ''], _
['†', '†', ''], _
['‡', '‡', ''], _
['ˆ', 'ˆ', ''], _
['‰', '‰', ''], _
['Š', 'Š', ''], _
['‹', '‹', '<'], _
['Œ', 'Œ', ''], _
['', '', ''], _
['Ž', 'Ž', ''], _
['', '', ''], _
['', '', ''], _
['‘', '‘', ''], _
['’', '’', ''], _
['“', '“', ''], _
['”', '”', ''], _
['•', '•', ''], _
['–', '–', ''], _
['—', '—', ''], _
['˜', '˜', ''], _
['™', '™', ''], _
['š', 'š', ''], _
['›', '›', '>'], _
['œ', 'œ', 'œ'], _
['', '', ''], _
['ž', 'ž', ''], _
['Ÿ', 'Ÿ', 'Ÿ'], _
[' ', ' ', ' '], _
['¡', '¡', '¡'], _
['¢', '¢', '¢'], _
['£', '£', '£'], _
['¤', '¤', '¤'], _
['¥', '¥', '¥'], _
['¦', '¦', '¦'], _
['§', '§', '§'], _
['¨', '¨', '¨'], _
['©', '©', '©'], _
['ª', 'ª', 'ª'], _
['«', '«', '«'], _
['¬', '¬', '¬'], _
['', '­', '­'], _
['®', '®', '®'], _
['¯', '¯', '&masr;'], _
['°', '°', '°'], _
['±', '±', '±'], _
['²', '²', '²'], _
['³', '³', '³'], _
['´', '´', '´'], _
['µ', 'µ', 'µ'], _
['¶', '¶', '¶'], _
['·', '·', '·'], _
['¸', '¸', '¸'], _
['¹', '¹', '¹'], _
['º', 'º', 'º'], _
['»', '»', '»'], _
['¼', '¼', '¼'], _
['½', '½', '½'], _
['¾', '¾', '¾'], _
['¿', '¿', '¿'], _
['À', 'À', 'À'], _
['Á', 'Á', 'Á'], _
['Â', 'Â', 'Â'], _
['Ã', 'Ã', 'Ã'], _
['Ä', 'Ä', 'Ä'], _
['Å', 'Å', 'Å'], _
['Æ', 'Æ', '&Aelig'], _
['Ç', 'Ç', 'Ç'], _
['È', 'È', 'È'], _
['É', 'É', 'É'], _
['Ê', 'Ê', 'Ê'], _
['Ë', 'Ë', 'Ë'], _
['Ì', 'Ì', 'Ì'], _
['Í', 'Í', 'Í'], _
['Î', 'Î', 'Î'], _
['Ï', 'Ï', 'Ï'], _
['Ð', 'Ð', 'ð'], _
['Ñ', 'Ñ', 'Ñ'], _
['Ò', 'Ò', 'Ò'], _
['Ó', 'Ó', 'Ó'], _
['Ô', 'Ô', 'Ô'], _
['Õ', 'Õ', 'Õ'], _
['Ö', 'Ö', 'Ö'], _
['×', '×', '×'], _
['Ø', 'Ø', 'Ø'], _
['Ù', 'Ù', 'Ù'], _
['Ú', 'Ú', 'Ú'], _
['Û', 'Û', 'Û'], _
['Ü', 'Ü', 'Ü'], _
['Ý', 'Ý', 'Ý'], _
['Þ', 'Þ', 'þ'], _
['ß', 'ß', 'ß'], _
['à', 'à', 'à'], _
['á', 'á', 'á'], _
['â', 'â', 'â'], _
['ã', 'ã', 'ã'], _
['ä', 'ä', 'ä'], _
['å', 'å', 'å'], _
['æ', 'æ', 'æ'], _
['ç', 'ç', 'ç'], _
['è', 'è', 'è'], _
['é', 'é', 'é'], _
['ê', 'ê', 'ê'], _
['ë', 'ë', 'ë'], _
['ì', 'ì', 'ì'], _
['í', 'í', 'í'], _
['î', 'î', 'î'], _
['ï', 'ï', 'ï'], _
['ð', 'ð', 'ð'], _
['ñ', 'ñ', 'ñ'], _
['ò', 'ò', 'ò'], _
['ó', 'ó', 'ó'], _
['ô', 'ô', 'ô'], _
['õ', 'õ', 'õ'], _
['ö', 'ö', 'ö'], _
['÷', '÷', '÷'], _
['ø', 'ø', 'ø'], _
['ù', 'ù', 'ù'], _
['ú', 'ú', 'ú'], _
['û', 'û', 'û'], _
['ü', 'ü', 'ü'], _
['ý', 'ý', 'ý'], _
['þ', 'þ', 'þ'], _
['ÿ', 'ÿ', 'ÿ'] ]
For $i = 1 To $__HTML_SpecialChars[0][0]
; If $__HTML_SpecialChars[$i][1] Then _
; $sString = StringReplace($sString, $__HTML_SpecialChars[$i][1], $__HTML_SpecialChars[$i][0], 0, 1)
If $__HTML_SpecialChars[$i][2] Then _
$sString = StringReplace($sString, $__HTML_SpecialChars[$i][2], $__HTML_SpecialChars[$i][0], 0, 1)
Next
Return $sString
EndFunc