Ich schreibe ein Skript, das einige spezifische Wörter zählt und gibt mir eine bestimmte Anzahl der Wörter.So drucken Sie '% d' & '% s' in einer Klasse in Python
Ich bin derzeit stecken in Druckdaten, aus der Klasse.
Meine nächste Aufgabe wäre diese Werte in eine Excel-Datei mit einem datengetriebenen Framework zu setzen.
Hier ist, was ich bisher getan haben:
a = driver.page_source
soup = BeautifulSoup(a, "html.parser")
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("Connot Test")
blockcode_completed = block_code.count("Completed")
blockcode_passwc = block_code.count("Pass With Concern")
blockcode_untested = block_code.count("Untested")
print '%s' + ' ' + '%d' %(tittle,blockcode_passed)
print '%s' + ' ' + '%d' %(tittle,blockcode_fail)
print "Apps Gateway(Untested)" + ' ' + '%d' %(blockcode_untested)
print "Apps Gateway(Blocked)" + ' ' + '%d' %(blockcode_blocked)
print "Apps Gateway(Retest)" + ' ' + '%d' %(blockcode_retest)
print "Apps Gateway(Cannot Test)" + ' ' + '%d' %(blockcode_cannot_test)
print "Apps Gateway(Completed)" + ' ' + '%d' %(blockcode_completed)
print "Apps Gateway(Pass With Concern)" + ' ' + '%d' %(blockcode_passwc)
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)
Der zweite Teil des Codes funktioniert, aber der erste Teil des Codes:
print '%s' + ' ' + '%d' %(tittle,blockcode_passed)
print '%s' + ' ' + '%d' %(tittle,blockcode_fail)
mir Fehler gibt:
print '%s' + ' ' + '%d' %(tittle,blockcode_passed)
TypeError: %d format: a number is required, not str
Das hat die Arbeit für mich getan. –