Mar-21-2024, 04:44 PM
Example,and use Requests and not urllib.
import requests url = "https://www.w3schools.com/xml/plant_catalog.xml" response = requests.get(url) with open('plant_catalog.xml', 'wb') as fp: fp.write(response.content)With a combination of Beautiful Soup that common to use with this.
import requests from bs4 import BeautifulSoup url = "https://www.w3schools.com/xml/plant_catalog.xml" response = requests.get(url) soup = BeautifulSoup(response.content, 'xml') first_common = soup.find('COMMON') print(first_common.text) # The whole plant_catalog.xml #print(soup) # Save to disk with open('plant_catalog.xml', 'w') as fp: fp.write(soup.prettify())
Output:Bloodroot