i am a python beginner and have written a code to download all the links in the url specified. Is there a better way to do this and is the below code correct?
#!/usr/bin/python3
import re
import requests
def get_page(url):
r = requests.get(url)
print(r.status_code)
content = r.text
return content
if __name__ =="__main__":
url = 'http://developer.android.com'
content = get_page(url)
content_pattern = re.compile('<a href=(.*?)>.*?</a>')
result = re.findall(content_pattern, content)
for link in result:
with open('download.txt', 'wb') as fd:
for chunk in r.iter_content(chunk_size):
fd.write(chunk)