1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| #! /usr/bin/env python
# -*- coding: utf-8 -*-
import Pmw
import urllib2
import re
import sys
import os
urlroot = 'http://recherche.fnac.com/Search/SearchResult.aspx?SCat=4!1&Search='
urlend = '&sft=1&submitbtn=OK'
Browserpath = '/usr/bin/opera'
from Tkinter import *
root = Tk()
master = Frame(root)
master.pack()
e = Entry(master)
e.pack()
e.focus_set()
answer = ""
def recup(adrs):
print "retrieving informations from"
print adrs
f=open('/var/www/fnactest.html','w')
start=0
for line in urllib2.urlopen(adrs):
if "données détaillée de l'article" in line:
start=1
print "we have found the begining of the table"
if start > 0:
print line
f.write(line)
if '</table' in line:
f.close
break
os.execl(Browserpath,'localhost/fnactest.html')
def callback(tag):
# This is called whenever the user clicks on a
# button in the RadioSelect widget.
print "function recup called"
print dic[tag]
recup( dic[tag])
def menu(dic):
# for k,v in dic.iteritems():
# print k,v
# for text in dic.keys:
# radio.add(text)
# Initialise Tkinter and Pmw.
root = Pmw.initialise(fontScheme = 'pmw1')
root.title('Click on the title')
# Create and pack a RadioSelect widget.
radio = Pmw.RadioSelect(
command = callback,
labelpos = 'w',
orient = 'vertical')
radio.pack(padx = 20, pady = 20)
# Add some buttons to the RadioSelect.
for k,v in dic.iteritems():
radio.add(k)
# radio.invoke('Vegetables')
# Create an exit button.
exit = Button(text = 'Cancel', command = root.destroy)
exit.pack(pady = 20)
def printanswer():
global answer
global dic
answer = e.get()
url = urlroot + answer + urlend
dic={}
previous=0
current=0
# f=open('/var/www/fnactest.html','w')
for line in urllib2.urlopen(url):
if previous > 0 :
current=1
previous=0
if '"lienInverse title"' in line:
previous = 1
#if 'google_adtest' in line:
# break
if current > 0:
if '?' in line:
newline=line.split('?')
val=newline[0].replace('<a href="','',1)
splitfurther=newline[1].split('>')
key=splitfurther[1].replace('</a','')
dic[key]=val
else:
newline=line.split('" class')
val=newline[0].replace('<a href="','',1)
splitfurther=newline[1].split('>')
key=splitfurther[1].replace('</a','')
#print(val)
#print(key)
#f.write(line)
#f.write("<br>")
current=0
#Now that the dictionary is created, we show the second menu
#Might be neeter if we define the second menu as a function
root.destroy()
menu(dic)
#f.close()
# print answer
# b1 = Button(master, text="SET", width=10, command=setanswer)
# b1.pack()
b2 = Button(master, text="Search", width=10, command=printanswer)
b2.pack()
root.mainloop() |
Partager