http_get.py
# -*- coding: UTF-8 -*-
import requests
import random
import string
import time
import threading
import datetime
def get(url):
res = requests.get(url)
print(res.text)
def random_str(randomlength):
str_list = [random.choice(string.digits + string.ascii_letters) for i in range(randomlength)]
return ''.join(str_list)
def get_url():
base_url = 'http://jingjinji.mschina2014.com/index/index/_like.html?id=%s&u=%s&t=%s'
user = random_str(26)
base_url = (base_url) % ('70', user, int(time.time() * 1000))
return base_url
def start():
num = 0
count = 10
c = 10
for i in range(count):
get(get_url())
num += 1
time.sleep(0.1)
c = c - 1
print(threading.currentThread().name + '--->还剩{%s}次,就完了,请耐心等待' % str(c) + '--->' + str(datetime.datetime.now()))
print(threading.currentThread().name + '--->一共点赞{%s}次' % str(num) + '--->' + str(datetime.datetime.now()))
def multi_thread(thread_num):
for i in range(thread_num):
threading.Thread(target=start(), args=()).start()
if __name__ == "__main__":
multi_thread(3)
分析点赞小程序
get_click_nums.py
# -*- coding: UTF-8 -*-
import requests
from bs4 import BeautifulSoup
import pymysql
import uuid
import datetime
import time
conn = pymysql.connect(
host="ip",
user="root",
password="root",
database="play",
charset="utf8")
sql = '''INSERT INTO compants (id, data_id, name, click_nums, says, create_date) VALUES ('%s', '%s', '%s', '%s',
'%s', '%s') '''
def get_contents():
url = 'http://jingjinji.mschina2014.com/index/index/like.html'
return requests.get(url)
def parse_xml(contents):
soup = BeautifulSoup(contents.text, 'lxml')
data = soup.find_all('li')
process_data(data)
def process_data(datas):
for data in datas:
nums = data.text
try:
name = data.contents[0].text
say = data.contents[2].text
click_nums = data.contents[4].next.text.split('票')[0]
id = data.contents[4].contents[1].attrs['data-id']
if int(id) > 47:
sql_exec = sql % (uuid.uuid4(), id, name, click_nums, say, str(datetime.datetime.now()))
print(sql_exec)
mysql(sql_exec)
except Exception as e:
print(e)
pass
def mysql(sql):
cursor = conn.cursor()
cursor.execute(sql)
conn.commit()
if __name__ == "__main__":
while True:
parse_xml(get_contents())
time.sleep(60)
requirement.txt
requests~=2.24.0
PyMySQL~=0.10.1
beautifulsoup4~=4.9.3
lxml~=4.6.2
start.sh
nohup python3 -u get_click_nums.py >nohup.click.log &
数据分析
select t.data_id, t.`name`, t.says, max(t.click_nums) from compants t group by t.data_id, t.`name`, t.says
order by length(max(t.click_nums)) desc;
select t.data_id, t.name, t.says,t.click_nums,t.create_date from compants t having t.data_id=70 order by t.data_id, t.create_date;
select t.data_id, t.name as 公司名, t.says as 公司标语,t.click_nums as 点赞数,min(t.create_date) as '最早点赞时间(美国时间)', max(t.create_date) as '最晚点赞时间(美国时间)' from compants t group by t.data_id, t.name, t.says,t.click_nums having t.data_id=70 order by t.data_id;
select t.data_id, t.name as 公司名, t.says as 公司标语,t.click_nums as 点赞数,group_concat(t.create_date) as '点赞时间(美国时间)' from compants t group by t.data_id, t.name, t.says,t.click_nums having t.data_id=70 order by t.data_id;