I have a python crawler which uses phanthomjs to crawl the sites and I am trying to stop loading 'css' contents from those webpages.I found a following code from various internet sources to stop 'CSS' loading, but that is not working .Please help me in fixing this issue.I also tried other solutions mentioned in stack overflow but that too didn't worked.
driver = webdriver.PhantomJS()
driver.command_executor._commands['executePhantomScript'] = ('POST', '/session/$sessionId/phantom/execute')
driver.execute('executePhantomScript', {'script': '''
var page = this;
page.onResourceRequested = function(requestData, request) {
if ((/http:\/\/.+?\.css/gi).test(requestData['https://www.whatismyip.com/']) || requestData.headers['Content-Type'] == 'text/css') {
console.log('The url of the request is matching. Aborting: ' + requestData['https://www.whatismyip.com/']);
request.abort();
}
''', 'args': []})
driver.get("https://www.whatismyip.com/")
ipaddress=driver.find_element_by_xpath("//div[@class='ip']").text
print ipaddress
driver.quit()