Skip to content

Instantly share code, notes, and snippets.

@bluzir
Created February 26, 2017 19:23
Show Gist options
  • Save bluzir/e28147c809dfc117dea6f36824cfd872 to your computer and use it in GitHub Desktop.
Save bluzir/e28147c809dfc117dea6f36824cfd872 to your computer and use it in GitHub Desktop.
import re
import requests
BASE_URL = 'http://archillect.com/{}'
headers = {
'User-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) '
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36',
'Refferer': 'https://vk.com/'
}
last_id = 107243
def main():
next_id = last_id + 1
response = requests.get(url=BASE_URL.format(next_id),
allow_redirects=False)
if response.status_code == 200:
image_url = re.findall('<img id="ii" src=(.*?)/>', response.text)[0]
print(image_url)
image = requests.get(url=image_url,
allow_redirects=False,
headers=headers,
stream=True)
if image.status_code == 200 or response.status_code == 304:
with open('images/{}.jpg'.format(next_id), 'wb') as f:
for chunk in image:
f.write(chunk)
else:
print(image.status_code)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment