mirror of
https://github.com/shmilylty/OneForAll.git
synced 2026-08-26 04:47:48 +08:00
移除fake-useragent依赖
This commit is contained in:
@@ -17,7 +17,6 @@ tldextract = "*"
|
|||||||
exrex = "*"
|
exrex = "*"
|
||||||
aiohttp = "*"
|
aiohttp = "*"
|
||||||
fire = "==0.2.1"
|
fire = "==0.2.1"
|
||||||
fake-useragent = "*"
|
|
||||||
bs4 = "*"
|
bs4 = "*"
|
||||||
cchardet = "*"
|
cchardet = "*"
|
||||||
lxml = "*"
|
lxml = "*"
|
||||||
|
|||||||
Generated
+1
-8
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"hash": {
|
"hash": {
|
||||||
"sha256": "cf68a50128345e403c4d2c25c59cf22490b83db80fc98da10dc41f515972e37e"
|
"sha256": "d95e37615ca48fe39a66e8c24eff76910c66b01b0739c0ab00ffa0f4df022107"
|
||||||
},
|
},
|
||||||
"pipfile-spec": 6,
|
"pipfile-spec": 6,
|
||||||
"requires": {
|
"requires": {
|
||||||
@@ -213,13 +213,6 @@
|
|||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==0.10.5"
|
"version": "==0.10.5"
|
||||||
},
|
},
|
||||||
"fake-useragent": {
|
|
||||||
"hashes": [
|
|
||||||
"sha256:c104998b750eb097eefc28ae28e92d66397598d2cf41a31aa45d5559ef1adf35"
|
|
||||||
],
|
|
||||||
"index": "pypi",
|
|
||||||
"version": "==0.1.11"
|
|
||||||
},
|
|
||||||
"fire": {
|
"fire": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:6865fefc6981a713d2ce56a2a2c92c56c729269f74a6cddd6f4b94d16ae084c9"
|
"sha256:6865fefc6981a713d2ce56a2a2c92c56c729269f74a6cddd6f4b94d16ae084c9"
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ async def fetch(session, url, semaphore):
|
|||||||
"""
|
"""
|
||||||
timeout = aiohttp.ClientTimeout(total=config.get_timeout)
|
timeout = aiohttp.ClientTimeout(total=config.get_timeout)
|
||||||
async with semaphore:
|
async with semaphore:
|
||||||
async with session.get(url, allow_redirects=config.get_redirects,
|
async with session.get(url,
|
||||||
|
allow_redirects=config.get_redirects,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
proxy=config.get_proxy) as resp:
|
proxy=config.get_proxy) as resp:
|
||||||
text = await resp.text()
|
text = await resp.text()
|
||||||
|
|||||||
@@ -5,10 +5,21 @@ import random
|
|||||||
import ipaddress
|
import ipaddress
|
||||||
import platform
|
import platform
|
||||||
import config
|
import config
|
||||||
from fake_useragent import UserAgent
|
|
||||||
from common.domain import Domain
|
from common.domain import Domain
|
||||||
from config import logger
|
from config import logger
|
||||||
|
|
||||||
|
user_agents = [
|
||||||
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
|
||||||
|
'(KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36',
|
||||||
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 '
|
||||||
|
'(KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36',
|
||||||
|
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 '
|
||||||
|
'(KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36',
|
||||||
|
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/68.0',
|
||||||
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) '
|
||||||
|
'Gecko/20100101 Firefox/68.0',
|
||||||
|
'Mozilla/5.0 (X11; Linux i586; rv:31.0) Gecko/20100101 Firefox/68.0']
|
||||||
|
|
||||||
|
|
||||||
def match_subdomain(domain, text, distinct=True):
|
def match_subdomain(domain, text, distinct=True):
|
||||||
"""
|
"""
|
||||||
@@ -20,7 +31,7 @@ def match_subdomain(domain, text, distinct=True):
|
|||||||
:return: 匹配结果
|
:return: 匹配结果
|
||||||
:rtype: set or list
|
:rtype: set or list
|
||||||
"""
|
"""
|
||||||
regexp = r'(?:[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?\.){0,}'\
|
regexp = r'(?:[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?\.){0,}' \
|
||||||
+ domain.replace('.', r'\.')
|
+ domain.replace('.', r'\.')
|
||||||
result = re.findall(regexp, text, re.I)
|
result = re.findall(regexp, text, re.I)
|
||||||
if not result:
|
if not result:
|
||||||
@@ -46,7 +57,7 @@ def gen_fake_header():
|
|||||||
"""
|
"""
|
||||||
生成伪造请求头
|
生成伪造请求头
|
||||||
"""
|
"""
|
||||||
ua = UserAgent()
|
ua = random.choice(user_agents)
|
||||||
ip = gen_random_ip()
|
ip = gen_random_ip()
|
||||||
headers = {
|
headers = {
|
||||||
'Accept': 'text/html,application/xhtml+xml,'
|
'Accept': 'text/html,application/xhtml+xml,'
|
||||||
@@ -58,7 +69,7 @@ def gen_fake_header():
|
|||||||
'DNT': '1',
|
'DNT': '1',
|
||||||
'Referer': 'https://www.google.com/',
|
'Referer': 'https://www.google.com/',
|
||||||
'Upgrade-Insecure-Requests': '1',
|
'Upgrade-Insecure-Requests': '1',
|
||||||
'User-Agent': ua.random,
|
'User-Agent': ua,
|
||||||
'X-Forwarded-For': ip,
|
'X-Forwarded-For': ip,
|
||||||
'X-Real-IP': ip
|
'X-Real-IP': ip
|
||||||
}
|
}
|
||||||
@@ -88,7 +99,7 @@ def split_list(ls, size):
|
|||||||
"""
|
"""
|
||||||
if size == 0:
|
if size == 0:
|
||||||
return ls
|
return ls
|
||||||
return [ls[i:i+size] for i in range(0, len(ls), size)]
|
return [ls[i:i + size] for i in range(0, len(ls), size)]
|
||||||
|
|
||||||
|
|
||||||
def get_domains(target):
|
def get_domains(target):
|
||||||
@@ -129,4 +140,3 @@ def get_semaphore():
|
|||||||
return 1000
|
return 1000
|
||||||
elif system == 'Darwin':
|
elif system == 'Darwin':
|
||||||
return 1000
|
return 1000
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user