60 535
Assignments Done
97,9%
Successfully Done
In April 2018

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.
Expert's answer
# Answer on Question #43112 - Programming - Python
import requests
from lxml import html
tree = html.parse("http://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 = 'http://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 = 'http://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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions