How to get html source code on sites that require Javascript without using Selenium WebDriver? Is there any other way?
Code:
def abrir_url(url):
link = ''
req = urllib2.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36')
req.add_header('Referer', 'http://www.redecanais.com/')
try:
response = urllib2.urlopen(req)
link = response.read().decode('utf-8' , 'ignore')
response.close()
except urllib2.URLError, e:
print str(e)
return link
url = 'http://www.filmesonlinegratis.com/page/1'
print abrir_url(url)
Code:
<html><title>You are being redirected...</title>
<noscript>Javascript is required. Please enable javascript before you are allowed to see this page.</noscript>