├── README.md └── Quick_ranking.py /README.md: -------------------------------------------------------------------------------- 1 | # Quick-ranking 2 | 3 | 网站快速排名v1.0,适用SEO 4 | 5 | 程序说明: 6 | 7 | 程序使用两个线程来运行,线程1在无忧代理上获取免费的ip地址,线程2执行排名函数,这么做是确保数据库中的ip不会被消耗完。 8 | 9 | 1、由于免费的代理多数是无效的,线程1在获取到ip后还会筛选出真正有效可用的ip地址,并将其存入数据库。 10 | 11 | 2、排名函数主要是从数据库中随机选择ip地址,然后通过该ip进入到需要访问的网站,使用random模块的作用是防止搜索引擎判断是机器操作 12 | 所以使用随机点击与滑动,虽然这么做不能确定是否真实有用,通过同一个网站反复使用该程序,对于排名兴许会有效果。 13 | 14 | 问题: 15 | 16 | 可能还存在用户体验等方面的问题,也可能包含搜索引擎算法等相关问题,网站快速排名程序会不断优化…… 17 | -------------------------------------------------------------------------------- /Quick_ranking.py: -------------------------------------------------------------------------------- 1 | import requests,time,random,pymysql,threading 2 | from selenium import webdriver 3 | from selenium.webdriver.common.action_chains import ActionChains 4 | from selenium.webdriver.chrome.options import Options 5 | 6 | def ip(): 7 | url = 'http://www.data5u.com/' 8 | chrome_options = Options() 9 | # 设置chrome浏览器无界面模式 10 | chrome_options.add_argument('--headless') 11 | driver = webdriver.Chrome(chrome_options=chrome_options) 12 | driver.get(url) 13 | ips = driver.find_elements_by_xpath('//ul[@class=\'l2\']/span[1]/li') # 找到ip模块 14 | dks = driver.find_elements_by_xpath('//ul[@class=\'l2\']/span[2]/li') # 端口 15 | lxs = driver.find_elements_by_xpath('//ul[@class=\'l2\']/span[4]/li') # 类型数据 16 | try: 17 | for i in range(len(ips)): 18 | proxies = { 19 | lxs[i].text:ips[i].text+':'+dks[i].text 20 | } 21 | 22 | r = requests.get('http://icanhazip.com', proxies=proxies, timeout=5)#判断ip是否有效 23 | if r.status_code == 200: 24 | #将有效的ip写入ip_data数据库 25 | sql_insert = "INSERT IGNORE INTO ip_data(ip,port,types) VALUES ('%s','%s','%s')"%(ips[i].text,dks[i].text,lxs[i].text) 26 | cursor.execute(sql_insert) 27 | conn.commit() 28 | conn.close() 29 | driver.close() 30 | except: 31 | pass 32 | driver.close() 33 | 34 | 35 | def xx(): 36 | url = 'http://so.m.sm.cn/s?q=' + keyword 37 | #查询数据库 38 | sql = "select * from ip_data" 39 | cursor.execute(sql) 40 | ips = [] 41 | for i in cursor.fetchall(): 42 | ips.append(i[0]) 43 | ip_data = random.choice(ips)#随机取出一个ip 44 | #从数据库中删除该数据 45 | delete = "DELETE FROM ip_data WHERE ip=%s" 46 | cursor.execute(delete,ip_data) 47 | conn.close() 48 | 49 | PROXY = ip_data # IP:PORT or HOST:PORT 50 | chrome_options = webdriver.ChromeOptions() 51 | chrome_options.add_argument('--proxy-server=%s' % PROXY) 52 | 53 | driver = webdriver.Chrome(chrome_options=chrome_options) 54 | driver.get(url) 55 | driver.set_page_load_timeout(10) 56 | 57 | 58 | #随机上下滑动函数 59 | def rand(): 60 | time.sleep(random.randint(2,5))#随机停留1-5秒 61 | for i in range(random.randint(2,6)): 62 | driver.execute_script("window.scrollTo(%s,%s)"%(random.randint(1,300),random.randint(1,300))) 63 | time.sleep(random.randint(1,3)) 64 | driver.execute_script("window.scrollTo(%s,%s)"%(random.randint(1,300),random.randint(1,300))) 65 | 66 | 67 | #随机点击函数 68 | def click(): 69 | for i in range(3): 70 | time.sleep(1) 71 | for i in range(1,3): 72 | driver.execute_script("window.scrollTo(%s,%s)" % (random.randint(1, 800), random.randint(1, 500))) 73 | time.sleep(random.randint(1, 3)) 74 | driver.execute_script("window.scrollTo(%s,%s)" % (random.randint(1, 800), random.randint(1, 500))) 75 | for j in range(30): 76 | time.sleep(0.5) 77 | x = random.randint(1,960) 78 | y = random.randint(1,1040) 79 | action = ActionChains(driver) 80 | action.move_by_offset(x, y).click() 81 | action.perform() 82 | 83 | 84 | num = 0 85 | while True: 86 | try: 87 | num += 1 88 | if num == 10: 89 | print("已查找到第十页没有数据,程序结束!") 90 | driver.close() 91 | break 92 | print("正在查找第",num,"页") 93 | divs = driver.find_elements_by_xpath('//h2/a') 94 | for i in divs: 95 | #如果指定元素在获取的元素里则点击 96 | if link in i.get_attribute('href'): 97 | i.click() 98 | click() 99 | rand() 100 | #如果不在则点击下一页 101 | driver.find_element_by_xpath('//div[@class="pager"]/a').click() 102 | except: 103 | driver.close() 104 | break 105 | 106 | 107 | if __name__ == '__main__': 108 | # 创建数据表 109 | conn = pymysql.connect('localhost', user='root', passwd='123456', db='ip') 110 | cursor = conn.cursor() 111 | 112 | # cursor.execute('DROP TABLE IF EXISTS ip_data') 113 | # sql = """CREATE TABLE ip_data( 114 | # ip VARCHAR(255) NOT NULL, 115 | # port VARCHAR(255) NOT NULL, 116 | # types VARCHAR(255) NOT NULL, 117 | # PRIMARY KEY(ip)#ip主键 118 | # ) 119 | # """ 120 | # cursor.execute(sql) 121 | 122 | keyword = input("请输入搜索关键词:") 123 | link = input("请输入需要刷的域名:") 124 | thread = threading.Thread(target=ip) 125 | thread1 = threading.Thread(target=xx) 126 | thread.start() 127 | thread1.start() 128 | thread.join() 129 | thread1.join() 130 | --------------------------------------------------------------------------------