Answer the question
In order to leave comments, you need to log in
I can't get information from the script tag, what should I do?
Hello!
I want to extract the links of all images from a link, but I have a problem extracting information from the script tag
. The code is here:
import requests
import json
from bs4 import BeautifulSoup as BS
import re
# Ссылка на полную страницу
url = 'https://www.instagram.com/p/B5n2EXjF_1C/'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'}
r = requests.get(url, headers=headers, allow_redirects=True)
soup = BS(r.content, 'html.parser')
script = soup.find('script', attrs={'type':"text/javascript"}, text=re.compile('window._sharedData'))
data = json.loads(script.next)
image_url = data['display_url']
print(image_url)
Answer the question
In order to leave comments, you need to log in
You are trying to parse it as JSON, but there is no JSON. There's javascript.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question