Найти - Пользователи
Полная версия: Вести лог парсера
Начало » Python для новичков » Вести лог парсера
1
sanodin
Сегодня по тв клип показывали ru music ,клип один понравился ,зашел к ним на сайт http://www.rumusic.tv/ru/ , а там только показывают что на данный момент в эфире
Собрал такой код для парсинга,только не знаю как лог вести,что бы сохранялся весь результат…
или список создавать?

# -*- coding: utf-8 -*-
import webbrowser
from Tkinter import *
import re
import urllib2
import time
import lxml.html
import lxml.etree

def _ur(event):
webbrowser.open_new_tab('www.rumusic.tv')


def reader():
global label
while 1:
_url = "http://www.rumusic.tv/xml/clip.xml"
u = urllib2.urlopen(_url)
page=u.read()
u.close()
break
doc = lxml.html.document_fromstring(page)
def ter():
for bold_tag in doc.getiterator(tag='clipname'):

return bold_tag.text
def top():
for bold_tag in doc.getiterator(tag='program'):
print bold_tag.text
return bold_tag.text

label["text"]="Musik-Clip: %s" %(ter())
flabel["text"]="> %s" %(top())
root.after(10000, reader)

root=Tk()
btn = Button(root,
text="RU Music",
width=10,height=2,
bg="yellow",fg="black")
btn.bind("<Button-1>", _ur)
btn.pack()
label=Label(root, text="******:")
label.pack(anchor=W)
flabel=Label(root, text="******:")
flabel.pack(anchor=W)
reader()
root.title("RU Music")
root.mainloop()
sanodin
Воооо….то что надо…спасибо

# -*- coding: utf-8 -*-
import webbrowser
from Tkinter import *
import re
import urllib2
import time
import lxml.html
import lxml.etree
import logging







def _ur(event):
webbrowser.open_new_tab('www.rumusic.tv')

def tick():#часы
global time1
# get the current local time from the PC
time2 = time.strftime('%H:%M:%S')
# if time string has changed, update it
if time2 != time1:
time1 = time2
clock.config(text=time2)
return time1
# calls itself every 200 milliseconds
# to update the time display as needed
# could use >200 ms, but display gets jerky
clock.after(200, tick)


def reader():
global label
while 1:
_url = "http://www.rumusic.tv/xml/clip.xml"
u = urllib2.urlopen(_url)
page=u.read()
u.close()
break
doc = lxml.html.document_fromstring(page)
def ter():
for bold_tag in doc.getiterator(tag='clipname'):

return bold_tag.text
def top():
for bold_tag in doc.getiterator(tag='program'):
print bold_tag.text
return bold_tag.text

label["text"]="Musik-Clip: %s" %(ter())
flabel["text"]="> %s" %(top())
root.after(10000, reader)

LOG_FILENAME = 'logging_example.out' # лог...
logging.basicConfig(filename=LOG_FILENAME,
level=logging.DEBUG,
)

logging.debug(ter())
logging.debug(top())
logging.debug(tick())
f = open(LOG_FILENAME, 'rt')
try:
body = f.read()
finally:
f.close() # ...лог





root=Tk()
time1 = ''
clock = Label(root, font=('times', 20, 'bold'), bg='green')
clock.pack(fill=BOTH, expand=1)



tick()
btn = Button(root,
text="RU Music",
width=10,height=2,
bg="yellow",fg="black")
btn.bind("<Button-1>", _ur)
btn.pack()
label=Label(root, text="******:")
label.pack(anchor=W)
flabel=Label(root, text="******:")
flabel.pack(anchor=W)
reader()
root.title("RU Music")
root.mainloop()
Только вот проблема,собрал cx_Freeze программу,запускаю под виндой .exe и ничего…что то не так может собралось?
sanodin
Все,получилось,собрал с помощью py2exe
Только некоторые библиотеки ручками прописал,оказывается не хватало двух модулей
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB