Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using BeautifulSoup for finding scripts

The code below was working as of a few days ago, but now it is only finding the first script for the url

url = 'https://understat.com/team/{}/2022'.format('Brentford')
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
scripts = soup.find_all('script')
scripts

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try to set a cookie when accessing the page:

import requests
from bs4 import BeautifulSoup

url = "https://understat.com/team/{}/2022".format("Brentford")

response = requests.get(url, cookies={"beget": "begetok"})  # <-- note the cookies= parameter
soup = BeautifulSoup(response.content, "html.parser")
scripts = soup.find_all("script")

print(scripts)

Prints:


...

                                        window.onload = function() { (adsbygoogle = window.adsbygoogle || []).push({}); }
                        </script>, <script defer="" src="js/date.format.min.js?v=2" type="text/javascript"></script>, <script defer="" src="js/calendar.js?v=2.1" type="text/javascript"></script>, <script defer="" src="js/team.js?v=2.5" type="text/javascript"></script>]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading