Basically i need to parse all src="" links from all <script> tags in HTML.
<script src="path/to/example.js" type="text/javascript"></script>
Unfortunately, bs4 cannot do that. Any ideas how can i achieve this?
I would condense and use script[src] to ensure script has src attribute
import requests
from bs4 import BeautifulSoup as bs
r = requests.get('http://example.com').content
soup = bs(r, 'lxml') # 'html.parser' if lxml not installed
srcs = [item['src'] for item in soup.select('script[src]')]
python test = soup.find_all('script') links = [link['src'] for link in test]and recieved an errorpython KeyError: 'src'This example worked fine with other tags[link['src'] for link in test if 'src' in link]