日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python selenium webdriver_Python:selenium.webdriver问题(服务器上没有X)

發(fā)布時(shí)間:2025/3/15 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python selenium webdriver_Python:selenium.webdriver问题(服务器上没有X) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我拼湊了以下腳本,以在遠(yuǎn)程Asterisk / Vicidial服務(wù)器上生成每日?qǐng)?bào)告.該腳本從報(bào)告中獲取源代碼,執(zhí)行某種格式設(shè)置,將結(jié)果保存為文本文件,然后通過smtp發(fā)送給我的老板以供審核.我目前正在本地的cron作業(yè)上運(yùn)行腳本,并且腳本運(yùn)行良好,但是我希望能夠在VPS上運(yùn)行該腳本;問題是,該腳本會(huì)彈出Firefox窗口,并且VPS沒有X或任何類型的GUI,因此Firefox無法打開,并且無法檢索數(shù)據(jù).

需要澄清的是,我已經(jīng)安裝了Firefox和所有必需的模塊,并且VPS本質(zhì)上與我的本地計(jì)算機(jī)(bar X和GUI(Debian Lenny))相同.

如果有人可以提供有關(guān)如何修改此腳本的任何幫助,以使其在沒有X / GUI的情況下工作,將不勝感激!

謝謝,托比.

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+'

')

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()

總結(jié)

以上是生活随笔為你收集整理的python selenium webdriver_Python:selenium.webdriver问题(服务器上没有X)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。