Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
一键解析破解
const puppeteer = require('puppeteer');
const SCRIPTS = [
`() => {
Object.defineProperty(navigator, 'webdriver', {
get: () => false,
});
}`,
`() => {
// We can mock this in as much depth as we need for the test.
window.navigator.chrome = {
app: {
isInstalled: false,
},
webstore: {
onInstallStageChanged: {},
onDownloadProgress: {},
},
runtime: {
PlatformOs: {
MAC: 'mac',
WIN: 'win',
ANDROID: 'android',
CROS: 'cros',
LINUX: 'linux',
OPENBSD: 'openbsd',
},
PlatformArch: {
ARM: 'arm',
X86_32: 'x86-32',
X86_64: 'x86-64',
},
PlatformNaclArch: {
ARM: 'arm',
X86_32: 'x86-32',
X86_64: 'x86-64',
},
RequestUpdateCheckStatus: {
THROTTLED: 'throttled',
NO_UPDATE: 'no_update',
UPDATE_AVAILABLE: 'update_available',
},
OnInstalledReason: {
INSTALL: 'install',
UPDATE: 'update',
CHROME_UPDATE: 'chrome_update',
SHARED_MODULE_UPDATE: 'shared_module_update',
},
OnRestartRequiredReason: {
APP_UPDATE: 'app_update',
OS_UPDATE: 'os_update',
PERIODIC: 'periodic',
},
},
};
}`,
`
() => {
const originalQuery = window.navigator.permissions.query;
return window.navigator.permissions.query = (parameters) => (
parameters.name === 'notifications' ?
Promise.resolve({ state: Notification.permission }) :
originalQuery(parameters)
);
}`,
`() => {
// Overwrite the "plugins" property to use a custom getter.
Object.defineProperty(navigator, 'plugins', {
// This just needs to have "length > 0" for the current test,
// but we could mock the plugins too if necessary.
get: () => [1, 2, 3, 4, 5],
});
}`,
`() => {
const getParameter = WebGLRenderingContext.getParameter;
WebGLRenderingContext.prototype.getParameter = function(parameter) {
// UNMASKED_VENDOR_WEBGL
if (parameter === 37445) {
return 'Intel Open Source Technology Center';
}
// UNMASKED_RENDERER_WEBGL
if (parameter === 37446) {
return 'Mesa DRI Intel(R) Ivybridge Mobile ';
}
return getParameter(parameter);
};
}`,
`() => {
['height', 'width'].forEach(property => {
// store the existing descriptor
const imageDescriptor = Object.getOwnPropertyDescriptor(HTMLImageElement.prototype, property);
// redefine the property with a patched descriptor
Object.defineProperty(HTMLImageElement.prototype, property, {
...imageDescriptor,
get: function() {
// return an arbitrary non-zero dimension if the image failed to load
if (this.complete && this.naturalHeight == 0) {
return 20;
}
// otherwise, return the actual dimension
return imageDescriptor.get.apply(this);
},
});
});
}`,
`
() => {
// store the existing descriptor
const elementDescriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetHeight');
// redefine the property with a patched descriptor
Object.defineProperty(HTMLDivElement.prototype, 'offsetHeight', {
...elementDescriptor,
get: function() {
if (this.id === 'modernizr') {
return 1;
}
return elementDescriptor.get.apply(this);
},
});
}`
];
(async () => {
const browser = await puppeteer.launch({
headless:false,
args: [
"--start-maximized",
"--no-sandbox",
"--disable-infobars",
"--ignore-certificate-errors",
"--log-level=3",
"--enable-extensions",
"--window-size=1920,1080",
"--user-data-dir=./data-dir",
],
defaultViewport: null,
});
const page = await browser.newPage();
await page.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36");
for (let script of SCRIPTS){
page.evaluateOnNewDocument(script)
};
const videoURL = process.argv[2];
console.log(videoURL);
await page.goto('http://www.yijianjiexi.com/')
await page.setViewport({ width: 1680, height: 916 })
await page.waitForSelector('.header-main #url_input')
await page.click('.header-main #url_input')
await page.type('.header-main #url_input', videoURL);
await page.waitForSelector('.col-xs-12 #url_submit_icon')
await page.click('.col-xs-12 #url_submit_icon')
await page.waitForSelector('.panel #video0')
await page.click('.panel #video0')
const element = await page.$(".panel #video0");
const sourceURL = await page.evaluate(element => element.value, element);
console.log(sourceURL)
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
await sleep(3000);
await browser.close()
})()
@yifeikong

This comment has been minimized.

Copy link
Owner Author

yifeikong commented Jun 1, 2019

这个网站竟然还检测了是不是 headless 浏览器

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.