在excel中为python中的类变量向行中的单元格写入值
我一直在尝试将值写入excel工作表中的#1,从中生成数据。我没有得到任何错误或类似的东西,但在excel文件中也没有得到任何输出在excel中为python中的类变量向行中的单元格写入值,python,excel,python-2.7,beautifulsoup,xlwt,Python,Excel,Python 2.7,Beautifulsoup,Xlwt,我一直在尝试将值写入excel工作表中的#1,从中生成数据。我没有得到任何错误或类似的东西,但在excel文件中也没有得到任何输出 from xlwt import Workbook import requests from bs4 import BeautifulSoup import re from selenium import webdriver from xlwt import Workbook from collections import Counter driver = we
from xlwt import Workbook
import requests
from bs4 import BeautifulSoup
import re
from selenium import webdriver
from xlwt import Workbook
from collections import Counter
driver = webdriver.Firefox()
driver.get("fetch dashboard link")
login_test = driver.find_element_by_xpath('//*[@id="authContent"]/form/div/p[2]/a')
login_test.click()
driver.implicitly_wait(30)
a = driver.page_source
soup = BeautifulSoup(a, "html.parser")
wb = Workbook()
sheet1 = wb.add_sheet('Automation')
sheet1.write_merge(0,2,0,0,'#')
sheet1.write_merge(0,0,1,7,'Test Result')
sheet1.write(1,1,'Component')
sheet1.write(1,2,'Test Restult')
sheet1.write(1,3,'Pass')
sheet1.write(1,4,'Fail')
sheet1.write(1,5,'Cannot Test')
sheet1.write(1,6,'Pass With Concern')
sheet1.write(1,7,'Pending')
i = 3
j=1
for row_len in range (0,27):
sheet1.write(i,0,j)
i=i+1
j=j+1
class counter_class:
def count(self, tittle, block_code):
blockcode_passed = block_code.count("Passed")
blockcode_blocked = block_code.count("Blocked")
blockcode_fail = block_code.count("Failed")
blockcode_retest = block_code.count("Retest")
blockcode_cannot_test = block_code.count("Cannot Test")
blockcode_completed = block_code.count("Completed")
blockcode_passwc = block_code.count("Pass With Concern")
blockcode_untested = block_code.count("Untested")
##writing the count values fetched from the top to write it to a row in the excel file.
f_r=3
f_c=1
sheet1.write(f_r, f_c, tittle)
f_c= f_c + 2
sheet1.write(f_r, f_c, blockcode_passed)
f_c= f_c + 1
sheet1.write(f_r, f_c, blockcode_fail)
f_c= f_c + 1
sheet1.write(f_r, f_c, blockcode_cannot_test)
f_c= f_c + 1
sheet1.write(f_r, f_c, blockcode_cannot_test)
f_c= f_c + 1
sheet1.write(f_r, f_c, blockcode_passwc)
f_c= f_c + 1
sheet1.write(f_r, f_c, blockcode_untested)
f_c=1
f_r=4
print f_r
print f_c
wb.save('xlwtexample.xls')
##Apps gateway starts here
apps_gateway = soup.find_all("div", {"id":"group-3191427"})
apps_gateway_str = str(apps_gateway)
apps_gateway_obj=counter_class()
apps_gateway_obj.count("appsgateway",apps_gateway_str)
还有一种简单的方法可以找到单元格所指向的行/列吗
下面是我编写的用于计算html中特定单词的代码,这些值需要放在excel文件中
from xlwt import Workbook
import requests
from bs4 import BeautifulSoup
import re
from selenium import webdriver
from xlwt import Workbook
from collections import Counter
driver = webdriver.Firefox()
driver.get("fetch dashboard link")
login_test = driver.find_element_by_xpath('//*[@id="authContent"]/form/div/p[2]/a')
login_test.click()
driver.implicitly_wait(30)
a = driver.page_source
soup = BeautifulSoup(a, "html.parser")
wb = Workbook()
sheet1 = wb.add_sheet('Automation')
sheet1.write_merge(0,2,0,0,'#')
sheet1.write_merge(0,0,1,7,'Test Result')
sheet1.write(1,1,'Component')
sheet1.write(1,2,'Test Restult')
sheet1.write(1,3,'Pass')
sheet1.write(1,4,'Fail')
sheet1.write(1,5,'Cannot Test')
sheet1.write(1,6,'Pass With Concern')
sheet1.write(1,7,'Pending')
i = 3
j=1
for row_len in range (0,27):
sheet1.write(i,0,j)
i=i+1
j=j+1
class counter_class:
def count(self, tittle, block_code):
blockcode_passed = block_code.count("Passed")
blockcode_blocked = block_code.count("Blocked")
blockcode_fail = block_code.count("Failed")
blockcode_retest = block_code.count("Retest")
blockcode_cannot_test = block_code.count("Cannot Test")
blockcode_completed = block_code.count("Completed")
blockcode_passwc = block_code.count("Pass With Concern")
blockcode_untested = block_code.count("Untested")
##writing the count values fetched from the top to write it to a row in the excel file.
f_r=3
f_c=1
sheet1.write(f_r, f_c, tittle)
f_c= f_c + 2
sheet1.write(f_r, f_c, blockcode_passed)
f_c= f_c + 1
sheet1.write(f_r, f_c, blockcode_fail)
f_c= f_c + 1
sheet1.write(f_r, f_c, blockcode_cannot_test)
f_c= f_c + 1
sheet1.write(f_r, f_c, blockcode_cannot_test)
f_c= f_c + 1
sheet1.write(f_r, f_c, blockcode_passwc)
f_c= f_c + 1
sheet1.write(f_r, f_c, blockcode_untested)
f_c=1
f_r=4
print f_r
print f_c
wb.save('xlwtexample.xls')
##Apps gateway starts here
apps_gateway = soup.find_all("div", {"id":"group-3191427"})
apps_gateway_str = str(apps_gateway)
apps_gateway_obj=counter_class()
apps_gateway_obj.count("appsgateway",apps_gateway_str)