如何从python selenium数据构建动态表?
我试图生成一个动态表,并在python selenium的帮助下通过电子邮件发送该表 使用WebDriver,我们能够获得所需字段的动态数据。但我无法在一个表格中列出这些数据。我尝试在循环中使用电子邮件功能如何从python selenium数据构建动态表?,python,selenium,Python,Selenium,我试图生成一个动态表,并在python selenium的帮助下通过电子邮件发送该表 使用WebDriver,我们能够获得所需字段的动态数据。但我无法在一个表格中列出这些数据。我尝试在循环中使用电子邮件功能 TotalBugs = int(TotalBugs) + 1 # BugList = [] for ID in range(1, TotalBugs): BugID = driver.find_element_by_xpath('/html[1]/body[1]/div[1]/sect
TotalBugs = int(TotalBugs) + 1
# BugList = []
for ID in range(1, TotalBugs):
BugID = driver.find_element_by_xpath('/html[1]/body[1]/div[1]/section[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/issuetable-web-component[1]/table[1]/tbody[1]/tr['+ str(ID) +']/td[2]/a[1]').get_attribute('href')
Summary = driver.find_element_by_xpath('/html[1]/body[1]/div[1]/section[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/issuetable-web-component[1]/table[1]/tbody[1]/tr['+ str(ID)+']/td[3]/p[1]').text
Reporter = driver.find_element_by_xpath('/html[1]/body[1]/div[1]/section[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/issuetable-web-component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[5]/span[1]/a[1]').text
Resolution = driver.find_element_by_xpath('/html[1]/body[1]/div[1]/section[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/issuetable-web-component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[8]').text
UpdatedDate = driver.find_element_by_xpath('/html[1]/body[1]/div[1]/section[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/issuetable-web-component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[10]/span[1]/time[1]').text
print(BugID, Summary, Reporter, Resolution, UpdatedDate)
tabular = [(BugID, Summary, Reporter, Resolution, UpdatedDate)]
for BugID, Summary, Reporter, Resolution, UpdatedDate in tabular:
tabular = [(BugID, Summary, Reporter, Resolution, UpdatedDate)]
message = "<thead><tr><th>Bug ID</th><th>Summary</th><th>Reporter</th><th>Resolution</th><th>Updated Date</th></tr></thead><tbody><tr><td>"+BugID+"</td><td>"+Summary+"</td><td>"+Reporter+"</td><td>"+Resolution+"</td><td>"+UpdatedDate+"</td></tr></tbody>"
SERVER = "xyz.smtp.com"
me = "xyz@xyz.com"
you = "xyz@xyz.com" # must be a list
msg = MIMEMultipart('alternative')
msg['Subject'] = "Daily report" + " - " + str(currentdate())
msg['From'] = me
msg['To'] = you
html = "<html> <body><p> Hi team</p><p>Please find the below mentioned tasks for today:</p><table class='table table-bordered ' border='1'>"+ message +"</table></body></html>"
# part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
# msg.attach(part1)
msg.attach(part2)
print(msg)
server = smtplib.SMTP(SERVER)
server.sendmail(me, you, msg.as_string())
server.quit()
试试下面的逻辑
message = "<thead><tr><th>Bug ID</th><th>Summary</th><th>Reporter</th><th>Resolution</th><th>Updated Date</th></tr></thead><tbody>"
TotalBugs = int(TotalBugs) + 1
# BugList = []
for ID in range(1, TotalBugs):
BugID = driver.find_element_by_xpath('//issuetable-web-component[1]/table[1]/tbody[1]/tr['+ str(ID) +']/td[2]/a[1]').get_attribute('href')
Summary = driver.find_element_by_xpath('//issuetable-web-component[1]/table[1]/tbody[1]/tr['+ str(ID)+']/td[3]/p[1]').text
Reporter = driver.find_element_by_xpath('//issuetable-web-component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[5]/span[1]/a[1]').text
Resolution = driver.find_element_by_xpath('//issuetable-web-component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[8]').text
UpdatedDate = driver.find_element_by_xpath('//issuetable-web-component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[10]/span[1]/time[1]').text
print(BugID, Summary, Reporter, Resolution, UpdatedDate)
newRow = "< tr > < td > " + BugID + " < / td > < td > " + Summary + " < / td > < td > " + Reporter + " < / td > < td > " + Resolution+" < / td > < td > "+UpdatedDate+" < / td > < / tr >"
message = message+newRow
message = message + "</tbody>"
SERVER = "xyz.smtp.com"
me = "xyz@xyz.com"
you = "xyz@xyz.com" # must be a list
msg = MIMEMultipart('alternative')
msg['Subject'] = "Daily report" + " - " + str(currentdate())
msg['From'] = me
msg['To'] = you
html = "<html> <body><p> Hi team</p><p>Please find the below mentioned tasks for today:</p><table class='table table-bordered ' border='1'>"+ message +"</table></body></html>"
# part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
# msg.attach(part1)
msg.attach(part2)
print(msg)
server = smtplib.SMTP(SERVER)
server.sendmail(me, you, msg.as_string())
server.quit()
message=“Bug IDSummaryReporterResolutionUpdate”
TotalBugs=int(TotalBugs)+1
#错误列表=[]
对于范围内的ID(1,TotalBugs):
BugID=driver。通过xpath('//issuetable web component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[2]/a[1]')查找元素。获取属性('href'))
Summary=driver。通过xpath('//issuetable web component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[3]/p[1]')查找元素。text
Reporter=driver。通过xpath('//issuetable web component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[5]/span[1]/a[1]')查找元素。text
Resolution=driver。通过xpath('//issuetable web component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[8]')查找元素。text
UpdateDate=driver。通过xpath('//issuetable web component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[10]/span[1]/time[1]')查找元素。text
打印(BugID、摘要、报告者、分辨率、更新日期)
newRow=“”+BugID+” “+Summary+”“+Reporter+” “+Resolution+” “+updatedate+” ”
message=message+newRow
消息=消息+“”
SERVER=“xyz.smtp.com”
我=”xyz@xyz.com"
你=”xyz@xyz.com“#必须是一个列表
msg=MIMEMultipart('alternative')
msg['Subject']=“每日报告”+“-”+str(currentdate())
msg['From']=我
msg['To']=您
html=“Hi team请查找下面提到的今天的任务:”+message+“”
#part1=MIMEText(文本“纯”)
part2=MIMEText(html,'html')
#附加信息(第1部分)
附加信息(第2部分)
打印(msg)
server=smtplib.SMTP(服务器)
sendmail(我,你,msg.as_string())
server.quit()
试试下面的逻辑
message = "<thead><tr><th>Bug ID</th><th>Summary</th><th>Reporter</th><th>Resolution</th><th>Updated Date</th></tr></thead><tbody>"
TotalBugs = int(TotalBugs) + 1
# BugList = []
for ID in range(1, TotalBugs):
BugID = driver.find_element_by_xpath('//issuetable-web-component[1]/table[1]/tbody[1]/tr['+ str(ID) +']/td[2]/a[1]').get_attribute('href')
Summary = driver.find_element_by_xpath('//issuetable-web-component[1]/table[1]/tbody[1]/tr['+ str(ID)+']/td[3]/p[1]').text
Reporter = driver.find_element_by_xpath('//issuetable-web-component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[5]/span[1]/a[1]').text
Resolution = driver.find_element_by_xpath('//issuetable-web-component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[8]').text
UpdatedDate = driver.find_element_by_xpath('//issuetable-web-component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[10]/span[1]/time[1]').text
print(BugID, Summary, Reporter, Resolution, UpdatedDate)
newRow = "< tr > < td > " + BugID + " < / td > < td > " + Summary + " < / td > < td > " + Reporter + " < / td > < td > " + Resolution+" < / td > < td > "+UpdatedDate+" < / td > < / tr >"
message = message+newRow
message = message + "</tbody>"
SERVER = "xyz.smtp.com"
me = "xyz@xyz.com"
you = "xyz@xyz.com" # must be a list
msg = MIMEMultipart('alternative')
msg['Subject'] = "Daily report" + " - " + str(currentdate())
msg['From'] = me
msg['To'] = you
html = "<html> <body><p> Hi team</p><p>Please find the below mentioned tasks for today:</p><table class='table table-bordered ' border='1'>"+ message +"</table></body></html>"
# part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
# msg.attach(part1)
msg.attach(part2)
print(msg)
server = smtplib.SMTP(SERVER)
server.sendmail(me, you, msg.as_string())
server.quit()
message=“Bug IDSummaryReporterResolutionUpdate”
TotalBugs=int(TotalBugs)+1
#错误列表=[]
对于范围内的ID(1,TotalBugs):
BugID=driver。通过xpath('//issuetable web component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[2]/a[1]')查找元素。获取属性('href'))
Summary=driver。通过xpath('//issuetable web component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[3]/p[1]')查找元素。text
Reporter=driver。通过xpath('//issuetable web component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[5]/span[1]/a[1]')查找元素。text
Resolution=driver。通过xpath('//issuetable web component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[8]')查找元素。text
UpdateDate=driver。通过xpath('//issuetable web component[1]/table[1]/tbody[1]/tr['+str(ID)+']/td[10]/span[1]/time[1]')查找元素。text
打印(BugID、摘要、报告者、分辨率、更新日期)
newRow=“”+BugID+” “+Summary+”“+Reporter+” “+Resolution+” “+updatedate+” ”
message=message+newRow
消息=消息+“”
SERVER=“xyz.smtp.com”
我=”xyz@xyz.com"
你=”xyz@xyz.com“#必须是一个列表
msg=MIMEMultipart('alternative')
msg['Subject']=“每日报告”+“-”+str(currentdate())
msg['From']=我
msg['To']=您
html=“Hi team请查找下面提到的今天的任务:”+message+“”
#part1=MIMEText(文本“纯”)
part2=MIMEText(html,'html')
#附加信息(第1部分)
附加信息(第2部分)
打印(msg)
server=smtplib.SMTP(服务器)
sendmail(我,你,msg.as_string())
server.quit()
untested,您可以使用pandas df存储数据,并在数据框上使用to_html方法。例如,No@Satish,它不会帮助我在一封电子邮件中获取所有这些数据。那么,我很糟糕,我相信一些专家会破解它。未经测试,您可以使用pandas df存储数据,并在数据框上使用to_html方法。例如,不@Satish,它不会帮助我在一封电子邮件中获得所有这些数据。那么,我的坏,我相信一些专家会破解它。