常见的网站为了防止被爬虫爬取,会禁用右键,这样就无法通过右键菜单查看源代码,但是我们可以通过 F12 开发者工具来解决这个问题。
打开浏览器开发者工具(F12),在 Console 栏中输入 JS 语句:
javascript:(function() { function R(a){ona = "on"+a; if(window.addEventListener) window.addEventListener(a, function (e) { for(var n=e.originalTarget; n; n=n.parentNode) n[ona]=null; }, true); window[ona]=null; document[ona]=null; if(document.body) document.body[ona]=null; } R("contextmenu"); R("click"); R("mousedown"); R("mouseup"); R("selectstart");})()
可能会碰到
F12 Warning: Don’t paste code into the DevTools Console that you don’t understand or haven’t reviewed yourself. This could allow attackers to steal your identity or take control of your computer. Please type ‘allow pasting’ below and hit Enter to allow pasting.的提示,输入allow pasting并回车即可。
中文的话按描述输入允许粘贴即可。
然后按回车键,在页面中右键就可以使用了。