-
Notifications
You must be signed in to change notification settings - Fork 0
/
uuid_req.py
149 lines (133 loc) · 4.74 KB
/
uuid_req.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# coding = utf-8
# -*- coding:utf-8 -*-
import json
import os
import re
import threading
import time
from urllib.parse import urlencode
import bs4 as bs4
import chardet
# from fake_useragent import UserAgent
import redis
import requests
from pyquery import PyQuery as pq
from data_saver import RedisClient
from concurrent.futures.thread import ThreadPoolExecutor
CONN = RedisClient('ccgp', 'd_link')
CONN1 = RedisClient('ccgp', 'filter_link')
CONN2 = RedisClient('ccgp', 'd_uuid')
URL = 'http://htgs.ccgp.gov.cn/GS8/contractpublish/detail/2c8382aa5513c90301551589cd7c0224?contractSign=0'
# URL = 'http://htgs.ccgp.gov.cn/GS8/contractpublish/detail/2c8382a96dcec594016e8cc65d0458e2?contractSign=0'
#
# Headers = {
# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
# 'Accept-Encoding': 'gzip, deflate',
# 'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
# 'Cache-Control': 'max-age=0',
# 'Connection': 'keep-alive',
# 'Content-Length': '227',
# 'Content-Type': 'application/x-www-form-urlencoded',
# 'DNT': '1',
# 'Host': 'htgs.ccgp.gov.cn',
# 'Origin': 'http://htgs.ccgp.gov.cn',
# 'Referer': 'http://htgs.ccgp.gov.cn/GS8/contractpublish/search',
# 'Upgrade-Insecure-Requests': '1',
# 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36'
# }
#
# DATA = {
# 'codeResult': 'bf903b3ff4056dd512f7d22a2936912a',
# 'searchContractCode': None,
# 'searchContractName': None,
# 'searchProjCode': None,
# 'searchProjName': None,
# 'searchPurchaserName': None,
# 'searchSupplyName': None,
# 'searchAgentName': None,
# 'searchPlacardStartDate': None,
# 'searchPlacardEndDate': None,
# 'code': '9w6s'
# }
proxy_pool_url = 'http://127.0.0.1:5010/get'
class reqpager( ):
def __init__(self):
self.data = None
# self.headers = Headers
# self.data = DATA
def get_proxy(self):
try:
response = requests.get(proxy_pool_url)
if response.status_code == 200:
proxy_url_content = response.content
encoding = chardet.detect(proxy_url_content)
proxy_url_context = proxy_url_content.decode(encoding['encoding'], 'ignore')
proxy_url_context1 = eval(proxy_url_context)
proxy_url = proxy_url_context1.get('proxy')
print(proxy_url)
return proxy_url
except ConnectionError:
return None
def page_req(self, url):
global proxy
try:
print(url)
print("Requsting Pages...")
proxy = self.get_proxy( )
proxies = {
'http': 'http://' + proxy
}
print(proxies)
ses = requests.Session( )
res = ses.post(url = url, timeout = 10, proxies = proxies)
encoding = chardet.detect(res.content)
html = res.content.decode(encoding['encoding'], 'ignore')
print('return html....')
self.parse_page(html)
# print(html)
# return html
except ConnectionError:
print('Connection timeout...')
def parse_title_date(self,context):
cs = context.split( )
pattern = re.compile(r'\d\d\d\d-\d\d-\d\d')
r = pattern.findall(context)
title = r[0]+cs[3]
print(title)
return title
def parse_page(self,content):
try:
doc = pq(content)
context = doc('tr td').text()
title = self.parse_title_date(context)
# jsonarr = json.dumps(cs, ensure_ascii = False)
# self.parse_date(context)
# print(type(cs))
# print(jsonarr)
# info = context.items()
# print(info)
# for i in info:
# print(i)
# print(context)
info = doc('.fileInfo div a')
# print(info)
for i in info.items( ):
if i.attr('onclick') != None:
# print(i.attr('onclick'))
t = i.attr('onclick')
pattern = re.compile(r"'(\S.*?-.*?-.*?\S)',")
r = pattern.findall(str(t))
CONN2.set(title, r[0])
print(r[0])
else:
print('[ERROR]uuid requesting failed...')
except Exception as e:
print(e)
def job(self):
# start=time.time()
URL_LIST = CONN1.scan()
u_num = CONN1.count()
with ThreadPoolExecutor(max_workers = 32) as executor:
executor.map(self.page_req, URL_LIST)
rq = reqpager()
rq.job()