Rosetta Code/Count examples: Difference between revisions

→‎{{header|Python}}: Update to Python 3; correct URLs; include User-Agent that won't result in a 403 from the API.
(Changed code to use "xmltree" and "xmlparser" as DOM modules are no longer provided. Changed the old URL by the right one.)
(→‎{{header|Python}}: Update to Python 3; correct URLs; include User-Agent that won't result in a 403 from the API.)
Line 2,193:
=={{header|Python}}==
 
<lang python>importfrom urllib.request import urlopen, xml.dom.minidomRequest
import xml.dom.minidom
 
r = Request(
x = urllib.urlopen("http 'https://www.rosettacode.org/wmw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml")',
headers={'User-Agent': 'Mozilla/5.0'})
x = urlopen(r)
 
tasks = []
for i in xml.dom.minidom.parseString(x.read()).getElementsByTagName("'cm"'):
t = i.getAttribute('title').replace("' "', "'_"')
yr = urllib.urlopenRequest("httpf'https://www.rosettacode.org/wmw/index.php?title=%s{t}&action=raw" % t.encode('utf-8')),
headers={'User-Agent': 'Mozilla/5.0'})
tasks.append( y.read().lower().count("{{header|") )
y = urlopen(r)
print t.replace("_", " ") + ": %d examples." % tasks[-1]
tasks.append( y.read().lower().count("b'{{header|"') )
print (t.replace("'_"', "' "') + "f': %d examples." % {tasks[-1]} examples.')
 
print "(f'\nTotal: %d{sum(tasks)} examples." % sum(tasks')</lang>
</lang>
 
=={{header|R}}==
1,480

edits