How to extract var (values) from <script> of html using beautifulsoup
问题 i am currently using import requests from bs4 import BeautifulSoup source = requests.get('www.randomwebsite.com').text soup = BeautifulSoup(source,'lxml') details= soup.find('script') this is returning me the following script. <script> var Url = "https://www.example.com"; if(Url != ''){code} else {code } </script> i want to have the output as following. https://www.example.com 回答1: import re text = """ <script> var Url = "https://www.example.com"; if(Url != ''){code} else {code } </script> ""