Answer to Question #43112 in Python for Komala Nityanandam

Question #43112
5. Write a code in Python to fetches all flag images on http://www.f-secure.com/en/web/corporation_global/contact/offices/europe and stores the images on disk, and save the image with file name based on the country name.
1
Expert's answer
2014-06-06T11:54:36-0400
# Answer on Question #43112 - Programming - Python
import requests
from lxml import html
tree = html.parse("https://www.f-secure.com/en/web/corporation_global/contact/offices/europe")
flags = tree.xpath("//img[contains(@src, 'ico-active-lang')]")
for flag in flags:
file_name = flag.attrib['src'].split('-')[-1]
src = 'https://www.f-secure.com' + flag.attrib['src']
r = requests.get(src)
with open(file_name, 'wb') as f:
f.write(r.content)
flags = tree.xpath("//img[contains(@src, 'corporation_global')]")
for flag in flags:
file_name = flag.attrib['src'].split('/')[-1]
src = 'https://www.f-secure.com' + flag.attrib['src']
r = requests.get(src)
with open(file_name, 'wb') as f:
f.write(r.content)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS