I try to scrape a page to get tag script only using python. This is the code:
from urllib.request import urlopen
from bs4 import BeautifulSoup as soup
import re
import numpy as np
url = urlopen("http:exampleofurl")
bsj = soup(url.read())
bsj.findAll('script')
This is example of the output:
<pre lang="Python">[<script>
document.documentElement.className = document.documentElement.className.replace( /(\s|$)/, "$1j" );
</script>,
<script>
var rtlLs = ['ar','yi'],
translationsHash = '3a',
wm = {
ready: false,
make: function(){
if ( !wm.ready ) {
wm.ready = true;
document.body.className += ' jsl';
}
}
};
window.setTimeout( wm.make, 100 ) </script>,
<script src="portal/ex.org/assets/js/index.js"></script>,
<script src="portal/ex.org/assets/js/gt-9.js"></script>]
But i want to get the contents of the script tags only, this is the output that i want:
document.documentElement.className = document.documentElement.className.replace( /(\s|$)/, "$1j" );
var rtlLs = ['ar','yi'],
translationsHash = '3a',
wm = {
ready: false,
make: function(){
if ( !wm.ready ) {
wm.ready = true;
document.body.className += ' jsl';
}
}
};
window.setTimeout( wm.make, 100 )
src="portal/ex.org/assets/js/index.js"
src="portal/ex.org/assets/js/gt-9.js"
There is no script tag there. What should i do to get the output?
And i want to save the output to a javascript file format.
How to save the output to a javascript file format?
What I have tried:
I tried to get script tags using python code, not the contents of the script tags only.