[Python] 纯文本查看 复制代码 # This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import _thread
import datetime
import hashlib
import pprint
import string
import struct
import threading
import time
import urllib
import requests
import pymssql, os
count = 10050000 # 声明全局变量
lock = threading.Lock() # 申请一把锁
def postcurl(i):
print("线程", i, "启动")
global count # 引用全局变量
while count < 10200000:
url = 'http://data.zz.baidu.com/urls?site=tool.sufeinet.com&token=密匙'
headers = {
'Content-Type': 'text/plain',
'User-Agent': 'curl/7.12.1',
'Referer': "http://tool.sufeinet.com"
}
# 加锁
lock.acquire()
count += 1
# 释放锁
lock.release()
# 服务器IP或服务器名称
server = "ip"
# 登陆数据库所用账号
user = "sa"
# 该账号密码
password = "pwd"
conn = pymssql.connect(server, user, password, database='数据库名')
cursor = conn.cursor()
# 向数据库发送SQL命令
cursor.execute("SELECT * FROM tablename where com_id=" + count.__str__())
row = cursor.fetchone()
curl = "http://tool.sufeinet.com/Encrypt/MD5.aspx?action=Decode&md5str="
while row:
curl = curl + urllib.parse.quote(row[1])
# 获取数据
str_html = requests.post(url, data=curl, headers=headers)
# 输出获取到的 as html
print("线程", i, "正在执行:", str_html.text, "-",row[1], "__", count)
row = cursor.fetchone()
print("循环结束")
conn.close()
# 主方法,程序的开始
if __name__ == '__main__':
try:
for i in range(1, 10):
time.sleep(1)
_thread.start_new_thread(postcurl, (i,))
except:
print("Error: 无法启 动线程")
while 1:
pass
|