最新公告
  • 欢迎您光临源码窝,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!立即加入我们
  • 本原始码转载于某破解论坛及圆柱博客,代码已经过整理,替代学习。

    小白勿扰,有python基础者使用更佳!

    免费分享给大家,代码无情人间有爱!

    运行环境

    1,python;

    2,动态拨号VPS;

    3,安装Mysql数据库并导入.sql文件;

    4,安装脚本需要的拓展库;

    快排python源码

    # -*- coding: utf-8 -*-from selenium import webdriver
    import time
    import requests
    import random
    import os
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    import traceback
    import urllib.request
    import pymysql
    import socket
    #import win32api #pip install pypiwin32
     
    #from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    #DesiredCapabilities.INTERNETEXPLORER['ignoreProtectedModeSettings'] = True
     
     
     
    #rasdial 宽带连接 19ab68----643534
    def connect():
        cmd_str = "rasdial %s %s %s" % (g_adsl_account['name'], g_adsl_account['username'], g_adsl_account['password'])
        os.system(cmd_str)
        time.sleep(5)
     
     
    #"rasdial 断开宽带连接 /disconnect"
    def disconnect():
        cmd_str = "rasdial %s /disconnect" % g_adsl_account['name']
        os.system(cmd_str)
        time.sleep(5)
         
    #获取ip地址 
    def get_ip():
        #return ['ip','address']
        fp = urllib.request.urlopen("http://ip.chinaz.com/getip.aspx")
        mybytes = fp.read()
        # note that Python3 does not read the html code as string
        # but as html code bytearray, convert to string with
        mystr = mybytes.decode("utf8")
        fp.close()
        ip = mystr.find("ip")
        add = mystr.find("address")
        ip = mystr[ip+4:add-2]
        address = mystr[add+9:-2]
        return [ip,address]
     
    #将ip地址插入数据库
    def insert_db(ipdate):
        #try:
            #获取一个数据库连接,注意如果是UTF-8类型的,需要制定数据库
            conn=pymysql.connect(host='localhost',user='root',passwd='',port=3306,charset='utf8')
            cur=conn.cursor()                              #获取一个游标对象
            #cur.execute("CREATE DATABASE zongzong")          #执行对应的SQL语句
            #exit()
            cur.execute("USE zongzong")
            #exit()
            #cur.execute("CREATE TABLE `ip_log` (`id` int(11) NOT NULL AUTO_INCREMENT,`ip` varchar(32) DEFAULT NULL,`address` varchar(64) DEFAULT NULL,`keyword` varchar(64) DEFAULT '',`url` varchar(256) DEFAULT '',`error` varchar(64) DEFAULT '',`created_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8;")
             
            #插入数据
            ISOTIMEFORMAT='%Y-%m-%d %X'
            ipdate.append( time.strftime( ISOTIMEFORMAT, time.localtime() ))
            cur.execute("INSERT INTO ip_log(ip,address,keyword,url,error,page,rank,created_at) VALUES(%s, %s, %s, %s, %s, %s, %s, %s)",ipdate)
             
            #cur.execute("SELECT * FROM ip_log")
            #data=cur.fetchall()
            #print(data)
                 
            cur.close()#关闭游标
            conn.commit()#向数据库中提交任何未解决的事务,对不支持事务的数据库不进行任何操作
            conn.close()#关闭到数据库的连接,释放数据库资源
        #except:
        #   print("发生异常")   
     
     
    #获取搜素出来的url
    def get_search_url(driver):
        urls = []
        real = []
        real_url = []
        click_link = []
        content = driver.find_element_by_css_selector("div[id=\"content_left\"]")
        links = content.find_elements_by_tag_name("a")
        for link in links:
            if link.get_attribute('class') == "c-showurl":
                real.append(link.text)
                url = link.get_attribute('href')
                urls.append(url)
                 
                #解密url
                header = requests.head(url).headers
                is_append = True
                for out_url in out_urls:
                    if out_url in header['location']:
                        is_append = False
                        break
                         
                if is_append == True:
                    real_url.append(header['location'])
                    #a标签对象
                    click_link.append(link)
                         
        #print(real)
        #print(urls)
        #return urls
        return [real_url,click_link]
         
         
    #function:解析加密url,剔除竞争对手的url
    # def get_real_url(urls):
        # real_url = []
        # for url in urls:
            # header = requests.head(url).headers
            # is_append = True
            # for out_url in out_urls:
                # if out_url in header['location']:
                    # is_append = False
                    # break
                 
            # if is_append == True:
                # real_url.append(header['location'])
        # return real_url
     
    #function 目标地址是否在某个list中
    def get_urlIndex(tagurl,urls):
        i = 0
        has = -1
        for url in urls:
            if tagurl in url:
                has = True
                return i
            i = i+1
        return has 
     
         
    #点击百度搜索内容下面的下一页
    def click_nextBtn(driver):
        div = driver.find_element_by_css_selector("div[id=\"page\"]")
        a = div.find_elements_by_tag_name("a")
        for item in a:
            print(item.text)
            if item.text == "下一页>":
                item.click()
         
        return driver
     
                 
     
     
    #随机点击
    def click_search_url(driver,items):
        urls = []
        real = []
        content = driver.find_element_by_css_selector("div[id=\"content_left\"]")
        links = content.find_elements_by_tag_name("a")
        i=0
        '''获取当前窗口'''
        nowhandle = driver.current_window_handle
        #allhandles=driver.window_handles
        #for handle in allhandles:
        #   print('....当前窗口....',handle.title)
        #exit()
         
        for link in links:
            if link.get_attribute('class') == "c-showurl":
                if i in items:
                    print("随机点击item:",i)
                    print(link.get_attribute('href'),link.text)
                    #exit()
                    link.click()
                    #停留在点击页面
                    time.sleep(random.randint(5,10))
                 
                    '''获取所有窗口'''
                    allhandles=driver.window_handles
                    #for handle in allhandles:
                    #   print('....当前窗口....',handle.title)
                    #exit()
                     
                    '''循环判断窗口是否为当前窗口'''
                    for handle in allhandles:
                        if handle != nowhandle:
                            print("切换到当前窗口")
                            driver.switch_to_window(handle)
                            print("title:",driver.title)
                            '''关闭当前窗口'''
                            driver.close()
                            '''回到原先的窗口'''
                            print("切换到原来的窗口")
                            driver.switch_to_window(nowhandle)
                            print("title:",driver.title)
                    print("本次随机点击完毕!")
                             
                i=i+1
     
                 
    #获取随机点击的搜索页random.randint(0
    def get_random_index(index,len):
        if index >= 8:
            random_index = [
                random.randint(0,4),random.randint(5,8)
            ]
        elif index>=4:
            random_index = [
                random.randint(0,3),random.randint(3,index)
            ]
        elif index>=0:
            random_index = [
                index
            ]
        elif index == -1:
            if len <=5:
                random_index = [
                    random.randint(0,5)
                ]
            else:
                random_index = [
                    #random.randint(0,4),random.randint(5,len)
                    random.randint(5,len)
                ]
        return random_index
     
     
     
    def getUA():
        uaList = [
            #360
            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
            #chrome
            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36",
            #"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36",
            "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36",
             
            #firefox
            #"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0",
            "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0",
             
            #ie11
            #"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko",
            #ie8 
            #"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; 4399Box.1357; 4399Box.1253; 4399Box.1357)",
             
            #2345王牌
            #"Chrome/39.0.2171.99 Safari/537.36 2345Explorer/6.5.0.11018",
             
            #搜狗
            #"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0",
            #opera
            "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 OPR/26.0.1656.60"
             
        ]
        headers = random.choice(uaList)
        return headers
     
    #屏幕浏览器窗口大小
    def getWindowSize():
        wind_size = [
            [1920,1080],
            [1600,900],
            [1280,720]
        ]
        headers = random.choice(wind_size)
        return headers
         
         
    #屏幕分辨率设置
    def setDisplay():
        display_size = [
            [1920,1080],
            [1680,1050],
            [1600,900],
            [1440,900],
            [1400,1050]
        ]
        d_size = random.choice(display_size)
         
        dm = win32api.EnumDisplaySettings(None, 0)
        dm.PelsWidth = d_size[0]
        dm.PelsHeight = d_size[1]
        dm.BitsPerPel = 32
        dm.DisplayFixedOutput = 0
        win32api.ChangeDisplaySettings(dm, 0)
     
         
    #拨号 19ab68----643534        
    g_adsl_account = {
        "name":"宽带连接",
        "username":"19ab68",
        "password":"643534"
    }
     
     
    #屏蔽点击的地址(竞争对手)
    out_urls = [
        'zhimo.yuanzhumuban.cc',
        'bbs.yuanzhumuban.cc',
            'http://money.163.com/15/0416/11/ANANRECC00253B0H.html'
    ]
     
     
    ##内页词
    targetURL = [
        ['http://www.ccooc.cn','站群程序'],
        ['t.ccooc.cn','站群养护'],
    ]
     
     
    for targetInfo in targetURL:
        try:
            #更换ip
            disconnect()
            connect()
            while(1):
                        try:
                            socket.gethostbyname("baidu.com")
                            break;
                        except:
                            disconnect()
                            connect()
            #更换分辨率
            #setDisplay()
            #启动浏览器
            #driver = webdriver.Ie()
            #driver = webdriver.Chrome()
            #driver = webdriver.Firefox()
            #设置PhantomJS的user_agent
            dcap = dict(DesiredCapabilities.PHANTOMJS)
            user_agent = getUA()
            print(user_agent)
            dcap["phantomjs.page.settings.userAgent"] = (
                    user_agent
            )
            #dcap["phantomjs.page.settings.resourceTimeout"] = (15000)
            dcap["phantomjs.page.settings.loadImages"] = (False)
            driver = webdriver.PhantomJS(desired_capabilities=dcap,service_args=['--load-images=no'])
            # UA = getUA()
            # print(UA)
            # webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.User-Agent'] = UA
            # driver = webdriver.PhantomJS()
            driver.implicitly_wait(30)
            #清cookie
            driver.delete_all_cookies()
            #driver.maximize_window() # 浏览器全屏显示
     
            #打开百度
            driver.get("http://www.baidu.com/")
            #driver.get("http://mch.weiba01.com/2.php")
             
            #设置浏览器窗口大小
            window_size = getWindowSize()
            driver.set_window_size(window_size[0], window_size[1])
                     
                     
            #搜索某个关键词
            print('打开百度成功',driver.title)
            target = targetInfo[0]
            keyword = targetInfo[1]
            if len(targetInfo)>2:
                    error_keyword = targetInfo[random.randint(2,len(targetInfo)-1)]
            print(">>>>>>>>>>>>>>>点击的关键词:",keyword,"--->目标地址:",target,">>>>>>>>>>>>>>>>>>>>")
             
            if len(targetInfo)>2:
                #模拟错误关键词
                print("点击错误关键词:",error_keyword);
                driver.find_element_by_id("kw").send_keys(error_keyword)
                time.sleep(2)
                driver.find_element_by_id("su").click()
                time.sleep(5)
                driver.find_element_by_id("kw").clear()
                time.sleep(2)
                print("错误关键词点击完毕")
            driver.find_element_by_id("kw").send_keys(keyword)
            #time.sleep(2)
     
            #点击搜索按钮
            print("...开始点击搜索按钮..")
            driver.find_element_by_id("su").click()
            #exit()
            print("...点击完毕..")
            time.sleep(2)
             
            #获取搜索结果页 0:着陆页  1:对应的链接对象
            urls_res = get_search_url(driver)
            real_urls = urls_res[0]
            #get_search_url(driver)[1][2].click()
             
            #real_urls = get_real_url(urls)
            print("搜索出来的可点击着陆页个数:",len(real_urls))
            print(real_urls)
            index = get_urlIndex(target,real_urls)
            print("目标index:",index)
     
            page = 1
            while index == -1 and page <= 4:
                if page == 1:
                    #点击前面的几个着陆页,模拟用户真实行为
                    items = get_random_index(index,len(real_urls))
                    #items = [4]
                    print(items)
                    click_search_url(driver,items)
                 
                #下一页
                driver = click_nextBtn(driver)
                time.sleep(3)
                urls_res = get_search_url(driver)
                real_urls = urls_res[0]
                #real_urls = get_real_url(urls)
                print(real_urls)
                index = get_urlIndex(target,real_urls)
                page = page+1
     
                 
                 
            if index > 4 and page == 1:
                #第一页,随机点击两个或一个
                int = random.randint(1,2)
                if int == 2:
                    items = get_random_index(index,len(real_urls))
                else:
                    items = [1]
                print(items)
                click_search_url(driver,items)
                 
            if page >=5:
                print("没有找到目标地址,放弃搜索...")
                print("关闭浏览器")
                driver.quit()
                time.sleep(5)
                data = get_ip()
                data.append(keyword)
                data.append(target)
                data.append("no_find")
                data.append(-1)
                data.append(-1)
                insert_db(data)
                continue
             
            print("目标在page",page,"当前排名:",index,real_urls[index])
            print("反问最后的目标页...")
            #driver.get(real_urls[index])
            urls_res[1][index].click()
            time.sleep(5)
             
            nowhandle = driver.current_window_handle
            allhandles = driver.window_handles
            #目标页和搜索栏目页切换下
            for handle in allhandles:
                if handle != nowhandle:
                    print("切换到当前窗口")
                    driver.switch_to_window(handle)
                    stime = random.randint(15,25)
                    #stime = 5;
                    print("目标页title:",driver.title,"停留-->",stime)
                    time.sleep(stime)
                    '''关闭当前窗口'''
                    driver.close()
                    '''回到原先的窗口'''
                    print("切换到原来的窗口")
                    driver.switch_to_window(nowhandle)
                    print("title:",driver.title)
             
             
            #time.sleep(random.randint(40,60))
            #time.sleep(5)
     
            #清除所有cookie
            print("打印cookie")
            cookie= driver.get_cookies()
            print(cookie)
            print("清除cookie")
            driver.delete_all_cookies()
            print("打印cookie:")
            cookie= driver.get_cookies()
            print(cookie)
     
            #关闭浏览器
            print("关闭浏览器")
            time.sleep(5)
            #driver.close()
            driver.quit()
            #time.sleep(5)
             
            #数据库记录运行信息
            data = get_ip()
            data.append(keyword)
            data.append(target)
            data.append("success")
            data.append(page)
            data.append(index)
            insert_db(data)
    
        except:
            data = get_ip()
            data.append(keyword)
            data.append(target)
            data.append("faild")
            data.append(-1)
            data.append(-1)
            insert_db(data)
    RIPRO主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
    源码窝 » 百度快排发包python原始核心文件

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
    提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。若排除这种情况,可在对应资源底部留言,或 联络我们.。
    找不到素材资源介绍文章里的示例图片?
    对于PPT,KEY,Mockups,APP,网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。
    源码窝
    提供全网最新资源,如有侵权联系删除

    发表评论

    售后服务:

    • 售后服务范围 1、商业模板使用范围内问题免费咨询
      2、源码安装、模板安装(一般 ¥50-300)服务答疑仅限SVIP用户
      3、单价超过200元的模板免费一次安装,需提供服务器信息。
      付费增值服务 1、提供dedecms模板、WordPress主题、discuz模板优化等服务请详询在线客服
      2、承接 WordPress、DedeCMS、Discuz 等系统建站、仿站、开发、定制等服务
      3、服务器环境配置(一般 ¥50-300)
      4、网站中毒处理(需额外付费,500元/次/质保三个月)
      售后服务时间 周一至周日(法定节假日除外) 9:00-23:00
      免责声明 本站所提供的模板(主题/插件)等资源仅供学习交流,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担,有部分资源为网上收集或仿制而来,若模板侵犯了您的合法权益,请来信通知我们(Email: 80027422@qq.com),我们会及时删除,给您带来的不便,我们深表歉意!

    Hi, 如果你对这款模板有疑问,可以跟我联系哦!

    联系作者

    发表评论

    售后服务:

    • 售后服务范围 1、商业模板使用范围内问题免费咨询
      2、源码安装、模板安装(一般 ¥50-300)服务答疑仅限SVIP用户
      3、单价超过200元的模板免费一次安装,需提供服务器信息。
      付费增值服务 1、提供dedecms模板、WordPress主题、discuz模板优化等服务请详询在线客服
      2、承接 WordPress、DedeCMS、Discuz 等系统建站、仿站、开发、定制等服务
      3、服务器环境配置(一般 ¥50-300)
      4、网站中毒处理(需额外付费,500元/次/质保三个月)
      售后服务时间 周一至周日(法定节假日除外) 9:00-23:00
      免责声明 本站所提供的模板(主题/插件)等资源仅供学习交流,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担,有部分资源为网上收集或仿制而来,若模板侵犯了您的合法权益,请来信通知我们(Email: 80027422@qq.com),我们会及时删除,给您带来的不便,我们深表歉意!

    Hi, 如果你对这款模板有疑问,可以跟我联系哦!

    联系作者
    • 28会员总数(位)
    • 593资源总数(个)
    • 0本周发布(个)
    • 0 今日发布(个)
    • 209稳定运行(天)

    提供最优质的资源集合

    立即查看 了解详情