Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: selenium.webdriver issue (no X on server)
    primarykey
    data
    text
    <p>I have pieced together the following script to generate a daily report on a remote Asterisk / Vicidial server. The script grabs the source from the report, performs some formatting, saves the result as a text file and then sends it via smtp to my boss for review. I'm currently running the script on a cron job locally and it works perfectly, however I would like to be able to run it on my VPS; problem being, the script pops a Firefox window and the VPS does not have X or any sort of GUI, and consequently, Firefox will not open, and the data cannot be retrieved.</p> <p>Just to clarify, I have Firefox and all required modules installed and the VPS is essentially identical to my local machine, bar X and GUI (Debian Lenny). </p> <p>If some someone could provide any sort of help on how to modify this script in order to work without X / GUI, it would be greatly appreciated!</p> <p>Thanks, Toby.</p> <pre><code>import contextlib import selenium.webdriver as webdriver import lxml.html as LH import lxml.html.clean as clean import csv import sys import smtplib from email.mime.text import MIMEText import email.mime.application import email import mimetypes import datetime date=datetime.date.today() url="http://myuser:mypass@ipaddress"+ str(date) + "some_other_string" ignore_tags=('script','noscript','style') with contextlib.closing(webdriver.Firefox()) as browser: browser.get(url) content=browser.page_source cleaner=clean.Cleaner() content=cleaner.clean_html(content) with open('vicidial_data.html','w') as f: f.write(content.encode('utf-8')) doc=LH.fromstring(content) with open('grab_raw.txt','w') as f: for elt in doc.iterdescendants(): if elt.tag in ignore_tags: continue text=elt.text or '' tail=elt.tail or '' words=' '.join((text,tail)).strip() if words: words=words.encode('utf-8') f.write(words+'\n') grab=open( 'grab_raw.txt', 'r' ) grab_list=grab.readlines() grab.close() del grab_list[0:21] grab_out=open("Vicidial_Report-"+str(date)+".txt", 'w') grab_out.writelines(grab_list) grab_out.close() msg=email.mime.Multipart.MIMEMultipart() msg['Subject']='Vicidial call-report' msg['From']='me@mycomapny.com' msg['To']='myboss@mycompany.com' body = email.mime.Text.MIMEText("Please find attached call-report for " + str(date)) msg.attach(body) filename= "Vicidial_Report-"+str(date)+".txt" fp=open(filename,'rb') att = email.mime.application.MIMEApplication(fp.read(),_subtype="text") fp.close() att.add_header('Content-Disposition','attachment',filename=filename) msg.attach(att) s = smtplib.SMTP('smtp.gmail.com') s.starttls() s.login('mygmaillogin@mycompanydomain.com','mypassword') s.sendmail('me@mycompanydomain.com',['myboss@mycompanydomain.com', 'someoneelse@mycompanydomain.com', ], msg.as_string()) s.quit() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload