The html returned is incomplete and half of the image links are not visible. Take a look at this.
Code:
import requests
from bs4 import BeautifulSoup
import json
import re
user_agent = {"User-Agent": "Mozilla/5.0 "
"(Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/80.0.3987.163 Safari/537.36"}
data = input("Search: ")
n = int(input("Number: "))
url = f'https://9gag.com/search?query={data}'
print(url, "\n")
source = requests.get(url,headers = user_agent).text
soup = BeautifulSoup(source,"lxml")
print(soup.prettify())
for images in soup.findAll("div",class_ = "post-cotainer",limit=n):
print(images,"\n")
The output is not showing the required "class = post-container" containing the image link:-