Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王景浩
zzsn_spider
Commits
0c9bb0cd
提交
0c9bb0cd
authored
8月 25, 2023
作者:
丁双波
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
下载pdf文件
上级
8be2a4ec
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
106 行增加
和
0 行删除
+106
-0
downPdf.py
tmp/usVsRussia/downPdf.py
+106
-0
ofac.py
tmp/usVsRussia/ofac.py
+0
-0
没有找到文件。
tmp/usVsRussia/downPdf.py
0 → 100644
浏览文件 @
0c9bb0cd
#下载pdf文件
import
os
from
datetime
import
time
import
pymysql
import
requests
import
urllib3
from
pymysql.converters
import
escape_string
from
base.BaseCore
import
BaseCore
urllib3
.
disable_warnings
(
urllib3
.
exceptions
.
InsecureRequestWarning
)
headers
=
{
'accept'
:
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
,
'accept-encoding'
:
'gzip, deflate, br'
,
'accept-language'
:
'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7'
,
'cache-control'
:
'max-age=0'
,
# 'cookie': 'maex=%7B%22v2%22%3A%7B%7D%7D; GUC=AQEBBwFjY49jkEIa8gQo&s=AQAAABw20C7P&g=Y2JIFQ; A1=d=AQABBBIpnmICEOnPTXZVmK6DESXgxq3niTMFEgEBBwGPY2OQYysNb2UB_eMBAAcIEimeYq3niTM&S=AQAAAobGawhriFKqJdu9-rSz9nc; A3=d=AQABBBIpnmICEOnPTXZVmK6DESXgxq3niTMFEgEBBwGPY2OQYysNb2UB_eMBAAcIEimeYq3niTM&S=AQAAAobGawhriFKqJdu9-rSz9nc; A1S=d=AQABBBIpnmICEOnPTXZVmK6DESXgxq3niTMFEgEBBwGPY2OQYysNb2UB_eMBAAcIEimeYq3niTM&S=AQAAAobGawhriFKqJdu9-rSz9nc&j=WORLD; PRF=t%3D6954.T%252BTEL%252BSOLB.BR%252BSTM%252BEMR%252BGT%252BAMD%252BSYM.DE%252BPEMEX%252BSGO.PA%252BLRLCF%252BSYNH%252B001040.KS; cmp=t=1669714927&j=0&u=1---',
'sec-ch-ua'
:
'"Chromium";v="106", "Google Chrome";v="106", "Not;A=Brand";v="99"'
,
'sec-ch-ua-mobile'
:
'?0'
,
'sec-ch-ua-platform'
:
"Windows"
,
'sec-fetch-dest'
:
'document'
,
'sec-fetch-mode'
:
'navigate'
,
'sec-fetch-site'
:
'same-origin'
,
'sec-fetch-user'
:
'?1'
,
'upgrade-insecure-requests'
:
'1'
,
'user-agent'
:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36'
}
baseCore
=
BaseCore
()
log
=
baseCore
.
getLogger
()
cnx
=
pymysql
.
connect
(
host
=
'114.115.159.144'
,
user
=
'caiji'
,
password
=
'zzsn9988'
,
db
=
'caiji'
,
charset
=
'utf8mb4'
)
cursor
=
cnx
.
cursor
()
def
get_file_name
(
headers
):
filename
=
''
if
'Content-Disposition'
in
headers
and
headers
[
'Content-Disposition'
]:
disposition_split
=
headers
[
'Content-Disposition'
]
.
split
(
';'
)
if
len
(
disposition_split
)
>
1
:
if
disposition_split
[
1
]
.
strip
()
.
lower
()
.
startswith
(
'filename='
):
file_name
=
disposition_split
[
1
]
.
split
(
'='
)
if
len
(
file_name
)
>
1
:
filename
=
file_name
[
1
]
if
not
filename
:
return
baseCore
.
getNextSeq
()
+
".pdf"
return
filename
def
downFile
(
url
,
path
):
try
:
baseCore
.
mkPath
(
path
)
proxy
=
{
'https'
:
'http://127.0.0.1:1080'
,
'http'
:
'http://127.0.0.1:1080'
}
response
=
requests
.
get
(
url
,
proxies
=
proxy
,
headers
=
headers
,
verify
=
False
,
timeout
=
10
)
fileName
=
get_file_name
(
response
.
headers
)
with
open
(
os
.
path
.
join
(
path
,
fileName
),
"wb"
)
as
pyFile
:
for
chunk
in
response
.
iter_content
(
chunk_size
=
1024
):
if
chunk
:
pyFile
.
write
(
chunk
)
except
Exception
as
e
:
log
.
error
(
f
"出错了----------{e}"
)
return
False
return
fileName
if
__name__
==
'__main__'
:
while
True
:
selectSql
=
f
"select id,url,website,ftype,stype,ttype from usvsrussia where state=0 order by id asc limit 1"
cursor
.
execute
(
selectSql
)
data
=
cursor
.
fetchone
()
if
data
:
id
=
data
[
0
]
url
=
data
[
1
]
website
=
data
[
2
]
ftype
=
data
[
3
]
stype
=
data
[
4
]
ttype
=
data
[
5
]
path
=
r'D:\美国VS俄罗斯制裁'
log
.
info
(
f
"开始处理{url}----"
)
if
website
:
path
=
os
.
path
.
join
(
path
,
website
)
if
ftype
:
path
=
os
.
path
.
join
(
path
,
ftype
)
if
stype
:
path
=
os
.
path
.
join
(
path
,
stype
)
if
ttype
:
path
=
os
.
path
.
join
(
path
,
ttype
)
fileName
=
downFile
(
url
,
path
)
if
fileName
:
updateSql
=
f
"update usvsrussia set state=1,pdf_name='{fileName}' ,pdf_path='{escape_string(path)}' where id={id}"
log
.
info
(
f
"开始处理{url}----处理ok"
)
else
:
updateSql
=
f
"update usvsrussia set state=2 where id={id}"
log
.
info
(
f
"开始处理{url}----处理error"
)
cursor
.
execute
(
updateSql
)
cnx
.
commit
()
else
:
log
.
info
(
"数据处理完毕,程序退出"
)
break
url
=
'https://ofac.treasury.gov/media/931946/download?inline'
log
.
info
(
f
"{url}----开始下载"
)
downFile
(
url
)
log
.
info
(
f
"{url}----开始下载,下载完成"
)
baseCore
.
close
()
cursor
.
close
()
cnx
.
close
()
\ No newline at end of file
tmp/usVsRussia/ofac.py
浏览文件 @
0c9bb0cd
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论