Skip to content

Instantly share code, notes, and snippets.

@Allwin12 Allwin12/
Created May 17, 2020

What would you like to do?
import requests
import urllib.parse
from PIL import Image
from io import BytesIO
from bs4 import BeautifulSoup
import re, sys
def image(username):
url = "{}/".format(username)
session = requests.session()
# header parameter is used to resolve the bad gateway 502 error
# html = session.get(url, headers={'User-Agent': 'Mozilla/5.0'}).text
# opening the URL and parsing it into BeautifulSoup
html = session.get(url, headers={'User-Agent': 'Mozilla/5.0'}).text
print("Page not found or No internet connection")
soup = BeautifulSoup(html, 'html.parser')
tags = soup.find_all('body')
# using regualr expression to extract the image URL
profile_pic_url_hd = re.findall(r"profile_pic_url_hd\":\"([\S]+?)\"", str(tags[0]))[0].replace(r'\u0026', '&')
response = session.get(profile_pic_url_hd, headers={'User-Agent': 'Mozilla/5.0'}).content
img ="{}.png".format(username))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.