Commit 73f224f8 by lichenggang

lib

parent 7cacf5cb
......@@ -10,14 +10,10 @@ __pycache__/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
......
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# import logging
import traceback
import requests
import token_lib
PLATFORM = "buerklin"
LEVEL = "C"
BACK_NUM = 0
MODE = "redis"
MAIN_NUM = THREAD_NUM = 1
url = "https://www.buerklin.com/buerklinws/oauth/token"
data = {
"client_id": "cws-client",
"client_secret": "2F6B7E48-E195-423F-BB48-B20E0E7C522A",
"grant_type": "password",
"username": "ichunt-apilogin",
"password": "GDCLC437OSMP960C9Q"
}
class DGTokenCrawler(token_lib.BaseTokenCrawler):
def get_params_list(self):
return [[i] for i in range(THREAD_NUM)]
def collect_token(self, key, num):
try:
tokens = []
obj = requests.post(url, data=data, timeout=30).json()
tokens.append(obj['access_token'])
return tokens
except Exception:
self.logger.error(traceback.format_exc())
if __name__ == "__main__":
o = requests.post(url, data=data, timeout=30).json()
print(o)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import traceback
from requests import sessions
import token_lib
PLATFORM = "corestaff"
LEVEL = "H"
BACK_NUM = 0
MODE = "redis"
MAIN_NUM = THREAD_NUM = 1
url = 'https://www.zaikostore.com/zaikostore/cn1/selectCurrency?currency=USD'
headers = {
'Host': "www.zaikostore.com",
'Connection': "keep-alive",
'Cache-Control': "max-age=0",
'Upgrade-Insecure-Requests': "1",
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36",
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
'Accept-Encoding': "gzip, deflate, br",
'Accept-Language': "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7",
# 'Cookie': "JSESSIONID=410247171C56E064668926D51A14FBA8.jvm1;",
}
class DGTokenCrawler(token_lib.BaseTokenCrawler):
def get_params_list(self):
return [[i] for i in range(THREAD_NUM)]
def collect_token(self, key, num):
try:
token = []
for i in range(10):
while 1:
try:
with sessions.Session() as session:
one = session.request('GET', url, headers=headers, timeout=10)
two = session.request('GET', url, headers=headers, timeout=10)
if two.status_code == 200:
jes = one.cookies.get('JSESSIONID')
token.append(jes)
self.logger.info('get %s cookie success!' % jes)
break
except Exception:
pass
return token
except Exception:
self.logger.error(traceback.format_exc())
if __name__ == "__main__":
pass
# with sessions.Session() as session:
# one = session.request('GET', url, headers=headers)
# print(one.cookies)
# two = session.request('GET', url, headers=headers)
# print(two.cookies)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import traceback
import requests
import token_lib
PLATFORM = "digikey"
LEVEL = "H"
BACK_NUM = 0
MODE = "redis"
MAIN_NUM = THREAD_NUM = 10
session_url = 'https://mobile.digikey.com/api/v2/session'
session_headers = {
'Host': "mobile.digikey.com",
'Content-Type': "application/json",
# 'Cookie': "sid=" + sid,
'Connection': "close",
'Accept': "application/json",
'User-Agent': "com.digikey.ios/4.22.1",
'Accept-Language': "zh",
'Cache-Control': "no-cache",
'Accept-Encoding': "gzip, deflate",
'cache-control': "no-cache",
}
data = '{"currency":{"id":0,"code":"CNY","name":""},"country":{"name":"","tld":"","lov":"","currencies":[],' \
'"iso":"CN","flags":{"isPostalCodeRequired":false,"isStateOrProvinceRequired":false,' \
'"hasEmbargo":false,"isCurrencyOption":true,"isDomestic":false,"isUSTerritory":false}}}'
data2 = {"country": {"name": "美国", "lov": "00",
"flags": {"hasEmbargo": False, "isPostalCodeRequired": True, "isStateOrProvinceRequired": True,
"isDomestic": True, "isUSTerritory": False, "isCurrencyOption": True},
"currencies": ["USD"], "iso": "US", "tld": "com"}, "currency": {"code": "USD"}}
proxies = {
"http": 'http://LIEXINHTT1:oK97IIl298@http-proxy-t3.dobel.cn:9180',
"https": 'http://LIEXINHTT1:oK97IIl298@http-proxy-t3.dobel.cn:9180',
}
class DGTokenCrawler(token_lib.BaseTokenCrawler):
def get_params_list(self):
return [[i] for i in range(THREAD_NUM)]
def collect_token(self, key, num):
try:
tokens = []
for i in range(50):
while 1:
try:
resp = requests.post(session_url, headers=session_headers, json=data2, timeout=20,
proxies=proxies)
sid = resp.cookies['sid']
print(sid, num, len(tokens))
# self.logger.info(sid)
break
except Exception:
self.logger.error(traceback.format_exc())
tokens.append(sid)
return tokens
except Exception:
self.logger.error(traceback.format_exc())
if __name__ == "__main__":
rep = requests.post(session_url, headers=session_headers, json=data2, timeout=20,
proxies=proxies)
print(rep.cookies['sid'])
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import time
# import logging
import traceback
import requests
from lxml.etree import HTML
import token_lib
PLATFORM = "mouser"
LEVEL = "H"
BACK_NUM = 0
MODE = "redis"
MAIN_NUM = 4
THREAD_NUM = 4
login = 'https://www.mouser.hk/MyMouser/MouserLogin.aspx'
coo1_base = 'AKA_A2=A; preferences=ps=hk&FF=&pl=zh-CHT&pc_hk=USDu; RT="sl=0&ss=1550562113354&tt=0&obo=0&bcn=%2F%2F36f11e2c.akstat.io%2F&sh=&dm=mouser.hk&si=6507a015-5be0-4f0a-bc17-6f52186f7d91&r=https%3A%2F%2Fwww.mouser.hk%2FMyMouser%2FMouserLogin.aspx&ul={0}"'
coo2_base = '; ak_bmsc={0}; ASP.NET_SessionId={1};'
accounts = [('Andygong2018', 'ichunt2018'),
('Lixiaoyan2018', 'ichunt2018'),
('Shenzhen IChunt Technology Co., Ltd.', 'ichunt201710'),
('Zhengjiafeng2018', 'ichunt2018'),
]
headers2 = {
'authority': "www.mouser.hk",
'upgrade-insecure-requests': "1",
'user-agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/71.0.3578.98 Safari/537.36",
'accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
'referer': "https://www.mouser.hk/",
'accept-encoding': "gzip, deflate, br",
'accept-language': "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7",
}
fail = '您的登入不成功。 請再試一次。'
succ = '歡迎'
def get_ts():
return int(time.time() * 1000)
proxies = {
"http": 'http://LIEXINHTT2:oK97IIl298@http-proxy-t3.dobel.cn:9180',
"https": 'http://LIEXINHTT2:oK97IIl298@http-proxy-t3.dobel.cn:9180',
}
class MGTokenCrawler(token_lib.BaseTokenCrawler):
def get_params_list(self):
return [[i] for i in accounts]
def collect_token(self, key, num):
print(key)
try:
tokens = []
for i in range(30):
try:
token = self.get_asp(key)
if token:
tokens.append(token)
except Exception:
self.logger.error(traceback.format_exc())
continue
return tokens
except Exception:
self.logger.error(traceback.format_exc())
def get_asp(self, key):
coo1 = coo1_base.format(get_ts())
h1 = self.get_headers(coo1)
resp = requests.get(login, headers=h1, timeout=30, allow_redirects=False, proxies=proxies)
h2 = self.get_headers('')
resp2 = requests.get(resp.headers['Location'], headers=h2, timeout=30, allow_redirects=False,
proxies=proxies)
asp = resp2.cookies['ASP.NET_SessionId']
self.logger.info('get asp %s' % asp)
return asp
def get_token(self, key):
coo1 = coo1_base.format(get_ts())
h1 = self.get_headers(coo1)
resp = requests.get(login, headers=h1, timeout=30, allow_redirects=False, proxies=proxies)
h2 = self.get_headers('')
resp2 = requests.get(resp.headers['Location'], headers=h2, timeout=30, allow_redirects=False,
proxies=proxies)
asp = resp2.cookies['ASP.NET_SessionId']
h3 = self.get_headers(coo1 + coo2_base.format(resp.cookies['ak_bmsc'], asp))
resp3 = requests.get(resp2.headers['Location'], headers=h3, timeout=30, allow_redirects=False,
proxies=proxies)
resp4 = requests.get(resp3.headers['Location'], headers=h3, timeout=30, allow_redirects=False,
proxies=proxies)
coo4 = ''
for k, v in resp4.cookies.items():
coo4 += k + '=' + v + '; '
doc = HTML(resp4.text)
vs = doc.xpath('//input[@id="__VIEWSTATE"]/@value')[0]
vsg = doc.xpath('//input[@id="__VIEWSTATEGENERATOR"]/@value')[0]
link = doc.xpath('//a[@id="lnkLogin"]/@href')[0]
# # print(vs, vsg, link)
login_data = self.get_login_data(vs, vsg, key[0], key[1])
headers2['cookie'] = coo4 + h3['cookie']
resp5 = requests.post(link, headers=headers2, timeout=30, data=login_data, allow_redirects=False,
proxies=proxies)
# print(resp5.text)
if succ in resp5.text:
# tokens.append(0)
self.logger.info('login success !')
return asp
else:
# me_main = resp5.cookies['ME_Main']
self.logger.info('login fail %s' % asp)
@staticmethod
def get_headers(coo):
headers1 = {
'authority': "www.mouser.hk",
'upgrade-insecure-requests': "1",
'user-agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/71.0.3578.98 Safari/537.36",
'accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
'referer': "https://www.mouser.hk/",
'accept-encoding': "gzip, deflate, br",
'accept-language': "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7",
'cache-control': "no-cache"
}
if coo:
headers1['cookie'] = coo
return headers1
@staticmethod
def get_login_data(vs, vsg, user_name, pass_wd):
login_data = {
'__EVENTTARGET': "",
'__EVENTARGUMENT': "",
'__VIEWSTATE': vs,
'__VIEWSTATEGENERATOR': vsg,
'__SCROLLPOSITIONX': "0",
'__SCROLLPOSITIONY': "0",
'ctl00$ContentMain$login$login$UserName': user_name,
'ctl00$ContentMain$login$login$Password': pass_wd,
'ctl00$ContentMain$login$login$RememberMe': "on",
'ctl00$ContentMain$login$login$LoginButton': "登入",
}
return login_data
if __name__ == "__main__":
pass
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re
import traceback
from urllib.parse import unquote
import requests
import token_lib
PLATFORM = "rutronik"
LEVEL = "4H"
BACK_NUM = 0
MODE = "redis"
MAIN_NUM = THREAD_NUM = 1
url = 'https://www.rutronik24.com/product/amph+icc/20020130-d081a01lf/1739583.html'
goods_headers = {
'Host': "www.rutronik24.com",
# 'Connection': "close",
'Cache-Control': "no-cache",
'Upgrade-Insecure-Requests': "1",
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/68.0.3440.106 Safari/537.36",
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
'Accept-Encoding': "gzip, deflate, br",
# 'Accept-Language': "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7,mt;q=0.6",
# 'cookie': cookie
}
class DGTokenCrawler(token_lib.BaseTokenCrawler):
def get_params_list(self):
return [[i] for i in range(THREAD_NUM)]
def collect_token(self, key, num):
try:
tokens = []
for i in range(10):
while 1:
try:
o = requests.get(url, headers=goods_headers, timeout=10)
r24 = unquote(o.cookies['R24REF'])
s32 = re.search('s:32:"([0-9a-f]*?)";', r24).group(1)
self.logger.info(s32)
tokens.append(s32)
break
except Exception:
self.logger.error(traceback.format_exc())
return tokens
except Exception:
self.logger.error(traceback.format_exc())
if __name__ == "__main__":
pass
# o = requests.get(url, headers=goods_headers, timeout=30)
# r24 = unquote(o.cookies['R24REF'])
# print(r24)
# s32 = re.search('s:32:"([0-9a-f]*?)";', r24).group(1)
# print(s32)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import traceback
import requests
import token_lib
PLATFORM = "verical"
LEVEL = "H"
BACK_NUM = 0
MODE = "redis"
MAIN_NUM = THREAD_NUM = 1
url = 'https://www.verical.com/static/generated/master.json?format=json'
class DGTokenCrawler(token_lib.BaseTokenCrawler):
def get_params_list(self):
return [[i] for i in range(THREAD_NUM)]
def collect_token(self, key, num):
try:
tokens = []
obj = requests.get(url, timeout=30).json()
rates = obj['currencyExchangeRatesView']['exchangeRates']
for rate in rates:
if rate['currencyCode'] == 'CNY':
self.logger.info('get CNY rate %f' % rate['exchangeRate'])
tokens.append(rate['exchangeRate'])
return tokens
except Exception:
self.logger.error(traceback.format_exc())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment