Skip to content

Commit

Permalink
增加selenium伪造头部的测试
Browse files Browse the repository at this point in the history
  • Loading branch information
luyishisi committed Jan 15, 2017
1 parent 2a53ae8 commit 920523b
Show file tree
Hide file tree
Showing 7 changed files with 2,017 additions and 0 deletions.
1,947 changes: 1,947 additions & 0 deletions 10.selement/forge-header/1.html

Large diffs are not rendered by default.

Binary file added 10.selement/forge-header/399.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 10.selement/forge-header/aa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions 10.selement/forge-header/forge-headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time

dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
"Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36"
)
dcap["phantomjs.page.settings.userAgent"] = (
"Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36"
)
dcap["phantomjs.page.customHeaders"] = {
"X-Forwarded-For":'110.216.12.194'
}

#page.driver.headers

print 'begin'
driver = webdriver.PhantomJS(desired_capabilities=dcap)

#driver.get("https://www.baidu.com/s?wd=ip")
driver.get("https://httpbin.org/get?show_env=1")
#driver.get("http://lbs.amap.com/getting-started/locate/")

time.sleep(5)
driver.get_screenshot_as_file('01.png')
print 'end'

driver.quit()
5 changes: 5 additions & 0 deletions 10.selement/forge-header/ghostdriver.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[INFO - 2017-01-13T08:01:38.570Z] GhostDriver - Main - running on port 49845
[INFO - 2017-01-13T08:01:38.895Z] Session [82fd2aa0-d966-11e6-b976-51fe51460522] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36","webSecurityEnabled":true}
[INFO - 2017-01-13T08:01:38.895Z] Session [82fd2aa0-d966-11e6-b976-51fe51460522] - page.customHeaders: - {}
[INFO - 2017-01-13T08:01:38.895Z] Session [82fd2aa0-d966-11e6-b976-51fe51460522] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"mac-10.11 (El Capitan)-64bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"},"phantomjs.page.settings.userAgent":"Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36"}
[INFO - 2017-01-13T08:01:38.895Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 82fd2aa0-d966-11e6-b976-51fe51460522
28 changes: 28 additions & 0 deletions 10.selement/forge-header/phantomjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var page = require('webpage').create();
system = require('system');

// console.log(system.args[0])
// console.log(system.args[1])
// console.log(system.args[2])
address = system.args[1];

page.settings.userAgent ="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"
page.customHeaders = {
"X-Forwarded-For": '110.216.12.194'
};

page.viewportsize={width:2000,height:2000};

page.onResourceReceived = function(response) {
console.log('Response (#' + response.id + ', stage "' + response.stage + '"): ' + JSON.stringify(response));
};

page.open('http://lbs.amap.com/getting-started/locate/', function() {
//page.open('http://ditu.baidu.com/', function() {
setTimeout(function(){
page.render(address+'.png');
console.log(address+'.png');
console.log(page.content);
phantom.exit();
},5000)
});
8 changes: 8 additions & 0 deletions 10.selement/forge-header/phantomjs_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


import os,re,time,MySQLdb,MySQLdb.cursors,urllib2,random
import requests
for i in range(300,400):
common = 'phantomjs' + ' phantomjs.js ' + str(i)
print time.ctime(),common
str_body = str(os.popen(common).read())

0 comments on commit 920523b

Please sign in to comment.