예제 #1
0
def access_Trade(url):

    driver = webdriver.Chrome(
        executable_path="/Users/charlesraymond/Documents/chromedriver")
    driver.get(url)
    sleep(3)

    driver.find_element_by_link_text("Trade").click()
    driver.find_element_by_id("symbol").send_keys(
        "UGAZ")  #.send_keys(Keys.ENTER)
    driver.find_element_by_link_text("Stocks & ETFs").click()
    sleep(3)
    select = Select(driver.find_element_by_id('action'))
    select.select_by_value('SELL')
    select = Select(driver.find_element_by_id('orderType'))
    select.select_by_value('MARKET')
예제 #2
0
def likeandcomment():
    # Liking the picture
    button_like = webdriver.find_element_by_xpath(
        '/html/body/div[3]/div[2]/div[1]/article/div[2]/section[1]/span[1]/button/span')
    button_like.click()
    likes = likes + 1
    sleep(randint(15, 30))
    # commenting the photo
    webdriver.find_element_by_xpath(
        '/html/body/div[3]/div[2]/div[1]/article/div[2]/section[1]/span[2]/button/span').click()
    sleep(randint(15, 30))
    comm = webdriver.find_element_by_xpath(
        '/html/body/div[3]/div[2]/div[1]/article/div[2]/section[3]/div[1]/form/textarea')
    sleep(10)
    comm.send_keys(
        'This is Great! Like your profile! Check out my profile, if you like it, follow and like it :) Hope to get your support! Keep The Good Work!:')
    sleep(10)
    comm.send_keys(Keys.ENTER)
    sleep(20)
    # Next pic
    webdriver.find_element_by_link_text('Dalej').click()
    sleep(randint(15, 30))
    print(likes)
예제 #3
0
def find(webdriver, by, css_selector_val):
    '''
    Wrapper function of selenium python to find an elment using locator and locator_value(css_selector_val)

    Arguments
    ---------

    webdriver       -   object of selenium.webdriver.chrome.webdriver.WebDriver .
    by              -   element locator name .
                        contraint:
                            expected value:-    id, name, xpath, link_text, partial_link_text, 
                                                tag_name, class_name, css_selector 
                        other value than the expected will return None
    css_selector_val-   value for the element locator i.e. arg 'by' 
                        example:- to find all elements with class_name=contact, value for css_selector_val is 'contact'
    
    Return
    ---------
    Webelement      -   if the value of arg 'by' is an expected value
    or
    None            -   if the value of arg 'by' is an unexpected value
    '''

    if by == 'id':
        return webdriver.find_element_by_id(css_selector_val)
    if by == 'name':
        return webdriver.find_element_by_name(css_selector_val)
    if by == 'xpath':
        return webdriver.find_element_by_xpath(css_selector_val)
    if by == 'link_text':
        return webdriver.find_element_by_link_text(css_selector_val)
    if by == 'partial_link_text':
        return webdriver.find_element_by_partial_link_text(css_selector_val)
    if by == 'tag_name':
        return webdriver.find_element_by_tag_name(css_selector_val)
    if by == 'class_name':
        return webdriver.find_element_by_class_name(css_selector_val)
    if by == 'css_selector':
        return webdriver.find_element_by_css_selector(css_selector_val)
    else:
        return None
예제 #4
0
        ).text

        if webdriver.find_element_by_xpath(
                '/html/body/div[4]/div[2]/div/article/header/div[2]/div[1]/div[2]/button'
        ).text == 'Seguir':

            print('Novo perfil seguido: {}'.format(perfil))
            # Fallow
            webdriver.find_element_by_xpath(
                '/html/body/div[4]/div[2]/div/article/header/div[2]/div[1]/div[2]/button'
            ).click()
            sleep(20)

            #  Line
            button_like = webdriver.find_element_by_xpath(
                '/html/body/div[4]/div[2]/div/article/div[2]/section[1]/span[1]/button'
            )
            button_like.click()
            sleep(20)

            # Next image
            webdriver.find_element_by_link_text('Próximo').click()
            sleep(20)

        else:
            print('Não encontrou botão de Seguir no perfil: {}'.format(perfil))

        i += 1

print('Script finalizado')
예제 #5
0
def goNextPage():
    webdriver.find_element_by_link_text(u"下一页>").click()
예제 #6
0
sleep(3)

notnow = webdriver.find_element_by_xpath('/html/body/div[1]/section/main/div/div/div/div/button')
notnow.click() #comment these last 2 lines out, if you don't get a pop up asking about notifications

#list hashtag yang postnya mau di like
#ini like top post di masing2 post
hashtag_list = ['teknikinformatika']
tag = -1
for hashtag in hashtag_list:
    tag += 1
    webdriver.get('https://www.instagram.com/explore/tags/'+ hashtag_list[tag] + '/')
    sleep(5)
    # klik thumbnail pertama
    first_thumbnail = webdriver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[1]/div/div/div[1]/div[1]/a/div')
    
    first_thumbnail.click()
    sleep(randint(1,2))    

    #sampai 10 post supaya tidak terlalu banyak
    try:        
        for x in range(1,10):
            #klik like
            button_like = webdriver.find_element_by_xpath('/html/body/div[5]/div[2]/div/article/div[3]/section[1]/span[1]/button')
            button_like.click()
            # button_next = webdriver.find_element_by_xpath('/html/body/div[4]/div[1]/div/div/a')
            button_next = webdriver.find_element_by_link_text('Next') #klik next post
            button_next.click()
            sleep(randint(1,10))    #diberi jeda agar tidak terlalu seperti bot
    except:
        continue
예제 #7
0
from  selenium import  webdriver
import time
webdriver=webdriver.Chrome()
webdriver.maximize_window()
webdriver.get(r"https://www.jd.com/?cu=true&utm_source=baidu-pinzhuan&utm_medium=cpc&utm_campaign=t_288551095_baidupinzhuan&utm_term=0f3d30c8dba7459bb52f2eb5eba8ac7d_0_0c537319b26d46ea908e84ec6cf07e92")
webdriver.find_element_by_xpath("//*[@id='ttbar-login']/a[1]").click()
webdriver.find_element_by_xpath("//*[@id='content']/div[2]/div[1]/div/div[3]/a").click()
webdriver.find_element_by_xpath("//*[@id='loginname']").send_keys("13008016530")
webdriver.find_element_by_xpath("//*[@id='nloginpwd']").send_keys("s1075576058")
webdriver.find_element_by_xpath("//*[@id='loginsubmit']").click()
time.sleep(8)

webdriver.find_element_by_xpath("//*[@id='key']").send_keys("电脑")
webdriver.find_element_by_xpath("//*[@id='search']/div/div[2]/button").click()
time.sleep(3)
webdriver.find_element_by_xpath("//*[@id='J_goodsList']/ul/li[1]/div/div[1]/a/img").click()
#加载所有的标签
all=webdriver.window_handles
print(all)
#切换标签
webdriver.switch_to.window(all[1])
webdriver.find_element_by_link_text("【新】8核i7 RTX2060 240Hz").click()
time.sleep(3)
webdriver.find_element_by_xpath("//*[@id='InitCartUrl']").click()
time.sleep(3)
webdriver.quit()
예제 #8
0
def master_code(webdriver, hashtag_list, iteration_ct):
    try:
        notnow = webdriver.find_element_by_css_selector(
            'body > div.RnEpo.Yx5HN > div > div > div.mt3GC > button.aOOlW.HoLwm'
        )
        notnow.click(
        )  # comment these last 2 lines out, if you don't get a pop up asking about notifications
    except:
        pass

    prev_user_list = [
    ]  # if it's the first time you run it, use this line and comment the two below
    # prev_user_list = pd.read_csv('20181203-224633_users_followed_list.csv', delimiter=',').iloc[:,1:2] # useful to build a user log
    # prev_user_list = list(prev_user_list['0'])

    new_followed = []
    tag = -1
    followed = 0
    likes = 0
    comments = 0

    for hashtag in hashtag_list:
        tag += 1
        webdriver.get('https://www.instagram.com/explore/tags/' +
                      hashtag_list[tag] + '/')
        sleep(5)
        first_thumbnail = webdriver.find_element_by_xpath(
            '//*[@id="react-root"]/section/main/article/div[1]/div/div/div[1]/div[1]/a/div'
        )

        first_thumbnail.click()
        sleep(randint(1, 2))
        # try:
        for x in range(1, iteration_ct):
            try:
                username = webdriver.find_element_by_xpath(
                    '/html/body/div[4]/div[2]/div/article/header/div[2]/div[1]/div[1]/h2/a'
                ).text

                if username not in prev_user_list:
                    # If we already follow, do not unfollow | go in loop based on probability
                    follow_prob = randint(1, 10)
                    if webdriver.find_element_by_xpath(
                            '/html/body/div[4]/div[2]/div/article/header/div[2]/div[1]/div[2]/button'
                    ).text == 'Follow' and follow_prob > 3:

                        if randint(1, 10) > 4:  # follow probability
                            webdriver.find_element_by_xpath(
                                '/html/body/div[4]/div[2]/div/article/header/div[2]/div[1]/div[2]/button'
                            ).click()
                            new_followed.append(username)
                            followed += 1

                        # Liking the picture
                        button_like = webdriver.find_element_by_css_selector(
                            'body > div._2dDPU.vCf6V > div.zZYga > div > article > div.eo2As > section.ltpMr.Slqrh > span.fr66n > button > svg'
                        )

                        button_like.click()
                        likes += 1
                        sleep(randint(18, 25))

                        # Comments and tracker
                        comm_prob = randint(1, 10)
                        print('{}_{}: {}'.format(hashtag, x, comm_prob))
                        if comm_prob > 4:
                            comments += 1
                            webdriver.find_element_by_xpath(
                                '/html/body/div[4]/div[2]/div/article/div[2]/section[3]'
                            ).click()
                            comment_box = webdriver.find_element_by_xpath(
                                '/html/body/div[4]/div[2]/div/article/div[2]/section[3]/div/form/textarea'
                            )
                            comment_list = [
                                'Really Cool!', 'Nice work :)',
                                'Nice gallery!!', 'So cool! :)', 'Great Click'
                            ]
                            comment_box.send_keys(comment_list[int(
                                comm_prob % len(comment_list))])
                            # Enter to post comment
                            comment_box.send_keys(Keys.ENTER)
                            sleep(randint(22, 28))
                    # Next picture
                    webdriver.find_element_by_link_text('Next').click()
                    sleep(randint(25, 29))
                else:
                    webdriver.find_element_by_link_text('Next').click()
                    sleep(randint(20, 26))
            except:
                pass
    for n in range(0, len(new_followed)):
        prev_user_list.append(new_followed[n])

    updated_user_df = pd.DataFrame(prev_user_list)
    updated_user_df.to_csv('{}_users_followed_list.csv'.format(
        strftime("%Y%m%d-%H%M%S")))
    print('Liked {} photos.'.format(likes))
    print('Commented {} photos.'.format(comments))
    print('Followed {} new people.'.format(followed))
    return [likes, comments, followed]
예제 #9
0
            )

            button_like.click()
            likes = likes + 1
            sleep(randint(60, 200))

            # commenting the photo
            #
            # webdriver.find_element_by_xpath('/html/body/div[3]/div[2]/div[1]/article/div[2]/section[1]/span[2]/button/span').click()
            # sleep(randint(60 , 200))
            # comm = webdriver.find_element_by_xpath('/html/body/div[3]/div[2]/div[1]/article/div[2]/section[3]/div[1]/form/textarea')
            # sleep(120)
            # comm.send_keys('This is Great! Check out my profile, if you like it, follow or like it :) Hope to get your support! :)')
            # sleep(randint(60 , 200))
            # comm.send_keys(Keys.ENTER)
            # sleep(200)

            #Next pic
            webdriver.find_element_by_link_text('Dalej').click()
            sleep(randint(60, 200))

            print(likes)

    except:
        continue

    else:
        print("good job")

print("Final Job")
예제 #10
0
def login_instapls():



 chromedriver_path = r'C:\Users\Orkideh\Downloads\chromedriver_win32/chromedriver.exe' # Change this to your own chromedriver path!
 webdriver = webdriver.Chrome(executable_path=chromedriver_path)
 sleep(2)
 webdriver.get('https://www.instagram.com/accounts/login/?source=auth_switcher')
 sleep(3)

 username = webdriver.find_element_by_name('username')
 username.send_keys(final_email)
 password = webdriver.find_element_by_name('password')
 password.send_keys(insta_pass3)

 button_login = webdriver.find_element_by_css_selector('body > div > section > main > div > article > div > div > div > form > div > button > div')
 button_login.click()
 sleep(3)

 notnow = webdriver.find_element_by_css_selector('body > div > div > div > div > div > button.aOOlW.HoLwm')
 notnow.click() #comment these last 2 lines out, if you don't get a pop up asking about notifications


 hashtag_list = ['vojood', 'gomshodim']

#############################################
 prev_user_list = []
 # - if it's the first time you run it, use this line and comment the two below

 #prev_user_list = pd.read_csv('20181203-224633_users_followed_list.csv', delimiter=',').iloc[:,1:2] # useful to build a user log
 #prev_user_list = list(prev_user_list['0'])

 new_followed = []
 tag = -1
 followed = 0
 likes = 0
 comments = 0

 for hashtag in hashtag_list:
     tag += 1
     webdriver.get('https://www.instagram.com/explore/tags/'+ hashtag_list[tag] + '/')
     sleep(5)
     first_thumbnail = webdriver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[1]/div/div/div[1]/div[1]/a/div')
    
     first_thumbnail.click()
     sleep(randint(1,2))    
     try:        
         for x in range(1,200):
             username = webdriver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/article/header/div[2]/div[1]/div[1]/h2/a').text
            
             if username not in prev_user_list:
                 # If we already follow, do not unfollow
                 if webdriver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/article/header/div[2]/div[1]/div[2]/button').text == 'Follow':
                    
                     webdriver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/article/header/div[2]/div[1]/div[2]/button').click()
                    
                     new_followed.append(username)
                     followed += 1

                     # Liking the picture
                     button_like = webdriver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/article/div[2]/section[1]/span[1]/button/span')
                    
                     button_like.click()
                     likes += 1
                     sleep(randint(18,25))

                     # Comments and tracker
                     comm_prob = randint(1,10)
                     print('{}_{}: {}'.format(hashtag, x,comm_prob))
                     if comm_prob > 7:
                         comments += 1
                         webdriver.find_element_by_xpath('/html/body/div/div/div/div/article/div/section/span/button/span').click()
                         comment_box = webdriver.find_element_by_xpath('/html/body/div/div/div/div/article/div/section/div/form/textarea')

                         if (comm_prob < 7):
                             comment_box.send_keys('dada eyval!')
                             sleep(1)
                         elif (comm_prob > 6) and (comm_prob < 9):
                             comment_box.send_keys('Nice work :)')
                             sleep(1)
                         elif comm_prob == 9:
                             comment_box.send_keys('Nice TRACK!!')
                             sleep(1)
                         elif comm_prob == 10:
                             comment_box.send_keys('So cool! :)')
                             sleep(1)
                         # Enter to post comment
                         comment_box.send_keys(Keys.ENTER)
                         sleep(randint(22,28))

                 # Next picture
                 webdriver.find_element_by_link_text('Next').click()
                 sleep(randint(25,29))
             else:
                 webdriver.find_element_by_link_text('Next').click()
                 sleep(randint(20,26))
     # some hashtag stops refreshing photos (it may happen sometimes), it continues to the next
     except:
         continue

 for n in range(0,len(new_followed)):
     prev_user_list.append(new_followed[n])
    
 updated_user_df = pd.DataFrame(prev_user_list)
 updated_user_df.to_csv('{}_users_followed_list.csv'.format(strftime("%Y%m%d-%H%M%S")))
 print('Liked {} photos.'.format(likes))
 print('Commented {} photos.'.format(comments))
 print('Followed {} new people.'.format(followed))
예제 #11
0
            comment_box.send_keys('Nice work :)')

            sleep(5)

        elif comm_prob == 3:

            comment_box.send_keys('Nice gallery!!')

            sleep(5)

        elif comm_prob == 4:

            comment_box.send_keys('So cool! :)')

            sleep(5)

                
        sleep(randint(4,6))
        comment_box.send_keys(Keys.ENTER)# Enter to post comment
        sleep(randint(22, 28))

        webdriver.find_element_by_link_text('Next').click()#clicking on next for next photo

        sleep(randint(25, 29))

###Developed by vinay patil



예제 #12
0
def start_script():
    '''initiates IGPY script to follow, comment, and like users based on hashtag_list (may need to update css_selector/xpath occasionally)'''

    hashtag_list = ['sanfrancisco', 'bayarea']

    #prev_user_list = [] #when instantiating for the first time
    prev_user_list = pd.read_csv('data/users_followed_list.csv')  #user log
    prev_user_list = list(prev_user_list['0'])

    new_followed = []
    tag = -1
    followed = 0
    likes = 0
    comments = 0

    for hashtag in hashtag_list:
        tag += 1
        webdriver.get('https://www.instagram.com/explore/tags/' +
                      hashtag_list[tag] + '/')
        sleep(5)
        first_thumbnail = webdriver.find_element_by_xpath(
            '//*[@id="react-root"]/section/main/article/div[1]/div/div/div[1]/div[1]/a/div'
        )

        first_thumbnail.click()
        sleep(randint(1, 2))

        # try:
        for x in range(1, 50):
            #print('username')
            username = webdriver.find_element_by_css_selector(
                'body > div._2dDPU.vCf6V > div.zZYga > div > article > header > div.o-MQd > div.PQo_0 > div.e1e1d > h2 > a'
            ).text

            if username not in prev_user_list:
                if webdriver.find_element_by_css_selector(
                        'body > div._2dDPU.vCf6V > div.zZYga > div > article > header > div.o-MQd > div.PQo_0 > div.bY2yH > button'
                ).text == 'Follow':
                    webdriver.find_element_by_css_selector(
                        'body > div._2dDPU.vCf6V > div.zZYga > div > article > header > div.o-MQd > div.PQo_0 > div.bY2yH > button'
                    ).click()
                    new_followed.append(username)
                    followed += 1

                    button_like = webdriver.find_element_by_css_selector(
                        'body > div._2dDPU.vCf6V > div.zZYga > div > article > div.eo2As > section.ltpMr.Slqrh > span.fr66n > button > span'
                    )
                    button_like.click()
                    likes += 1
                    sleep(randint(18, 25))

                    comm_prob = randint(1, 10)
                    print('{}_{}: {}'.format(hashtag, x, comm_prob))
                    if comm_prob > 7:
                        comments += 1
                        webdriver.find_element_by_css_selector(
                            'body > div._2dDPU.vCf6V > div.zZYga > div > article > div.eo2As > section.ltpMr.Slqrh > span._15y0l > button > span'
                        ).click()
                        comment_box = webdriver.find_element_by_css_selector(
                            'body > div._2dDPU.vCf6V > div.zZYga > div > article > div.eo2As > section.sH9wk._JgwE > div > form > textarea'
                        )

                        if (comm_prob < 7):
                            comment_box.send_keys('#yayarea nice!')
                            sleep(1)
                        elif (comm_prob > 6) and (comm_prob < 9):
                            comment_box.send_keys(
                                'if this isnt pure #yayarea then I dont know what is'
                            )
                        elif comm_prob == 9:
                            comment_box.send_keys('best of the #bayarea :)')
                        elif comm_prob == 10:
                            comment_box.send_keys('haha.. iconic #sf')
                        comment_box.send_keys(Keys.ENTER)
                        sleep(randint(22, 28))

                webdriver.find_element_by_link_text('Next').click()
                sleep(randint(25, 29))
            else:
                webdriver.find_element_by_link_text('Next').click()
                sleep(randint(20, 26))
    #     except:
    #         print('exception error')

    for n in range(0, len(new_followed)):
        prev_user_list.append(new_followed[n])

    updated_user_df = pd.DataFrame(prev_user_list)
    updated_user_df.to_csv('data/users_followed_list.csv')
    print('Liked {} photos.'.format(likes))
    print('Commented {} photos.'.format(comments))
    print('Followed {} new people.'.format(followed))
예제 #13
0
def behaviour(webdriver, hashtag_list):
    
    prev_user_list = pd.read_csv('users_followed_list.csv', delimiter=',').iloc[:,1:2] # useful to build a user log
    prev_user_list = list(prev_user_list['0'])

    new_followed = []
    tag = -1
    followed = 0
    likes = 0
    comments = 0

    for hashtag in hashtag_list:
        tag += 1
        webdriver.get('https://www.instagram.com/explore/tags/'+ hashtag_list[tag] + '/')
        sleep(5)
        first_thumbnail = webdriver.find_element_by_xpath('/html/body/div[1]/section/main/article/div[1]/div/div/div[1]/div[1]/a/div')
        
        first_thumbnail.click()
        sleep(randint(1,2))    
        try:        
            for x in range(1,200):
                username = webdriver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/header/div[2]/div[1]/div[1]/span/a').text
                
                # If we already follow, do not unfollow
                if username not in prev_user_list:               
                    if webdriver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/header/div[2]/div[1]/div[2]/button').text == 'Follow':
                        
                        # Follow new user
                        webdriver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/header/div[2]/div[1]/div[2]/button').click()
                        new_followed.append(username)                       
                        followed += 1
                        sleep(randint(3,6))
                        
                        # Liking the picture
                        webdriver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/div[3]/section[1]/span[1]/button').click()
                        likes += 1
                        sleep(randint(2,7))
                        
                        # Comments and tracker
                        comm_prob = randint(1,10)
                        print('{}_{}: {}'.format(hashtag, x,comm_prob))
                        if comm_prob > 0:
                            comments += 1
                            webdriver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/div[3]/section[3]/div/form').click()
                            comment_box = webdriver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/div[3]/section[3]/div/form/textarea')
                            
                            # Case of random comment
                            if comm_prob == 1:
                                comment_box.send_keys('Really cool!')
                                sleep(randint(3,7))
                            elif comm_prob == 2:
                                comment_box.send_keys('lovely <3')
                                sleep(randint(3,7))
                            elif comm_prob == 3:
                                comment_box.send_keys('Nice!')
                                sleep(randint(3,7))
                            elif comm_prob == 4:
                                comment_box.send_keys('So cute!! <3')
                                sleep(randint(3,7))
                            elif comm_prob == 5:
                                comment_box.send_keys('Love it!!!')
                                sleep(randint(3,7))
                            elif comm_prob == 6:
                                comment_box.send_keys('Wowww! :)')
                                sleep(randint(3,7))
                            elif comm_prob == 7:
                                comment_box.send_keys('Liked!')
                                sleep(randint(3,7))
                            elif comm_prob == 8:
                                comment_box.send_keys('Ahha! (y)')
                                sleep(randint(3,7))
                            elif comm_prob == 9:
                                comment_box.send_keys('So cool! :)')
                                sleep(randint(3,7))
                            elif comm_prob == 10:
                                comment_box.send_keys('Beautiful pic~~')
                                sleep(randint(3,7))
                                
                            # Post comment by send Enter key
                            comment_box.send_keys(Keys.ENTER)
                            sleep(randint(4,9))

                    # Go to next picture after like, follow, comment
                    webdriver.find_element_by_link_text('Next').click()
                    sleep(randint(10,18))
                
                # If user already been followed, go to next picture in the same hashtag
                else:
                    sleep(randint(2,5))
                    webdriver.find_element_by_link_text('Next').click()
                    sleep(randint(5,12))
                    
        # Some hashtag stops refreshing photos (it may happen sometimes), it continues to the next
        except:
            continue
    
    # Write list of user followed to csv
    for n in range(0,len(new_followed)):
        prev_user_list.append(new_followed[n])
        
    updated_user_df = pd.DataFrame(prev_user_list)
    updated_user_df.to_csv('users_followed_list.csv')
    print('Liked {} photos.'.format(likes))
    print('Commented {} photos.'.format(comments))
    print('Followed {} new people.'.format(followed))
    def instagram_likes_and_follows(self):

        webdriver = self.instagram_login()

        hashtag_list = self.hashtag_list

        # If the log file doesn't exist, likely on first run then instantiate an empty list for use
        # Otherwise use the log from previous runs
        if os.path.exists(f'{os.getcwd()}/users_followed_list.csv'):
            prev_user_list = pd.read_csv(f'{os.getcwd()}/users_followed_list.csv', delimiter=',')  # useful to build a user log
            prev_user_list = list(prev_user_list['Usernames'])

        else:
            prev_user_list = []

        
        new_followed = []
        tag = -1
        followed = 0
        likes = 0
        comments = 0

        for hashtag in hashtag_list:
            tag += 1
            webdriver.get('https://www.instagram.com/explore/tags/'+ hashtag_list[tag] + '/')
            sleep(5)
            first_thumbnail = webdriver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[1]/div/div/div[1]/div[1]/a/div')
            
            first_thumbnail.click()
            sleep(randint(1,2))    
          #  try:        
            for x in range(1,self.number_of_posts):
                #username = webdriver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/div[3]/div[1]/ul/div/li/div/div/div[2]/h2/div/span/a').text
                username = webdriver.find_element_by_css_selector('body > div._2dDPU.CkGkG > div.zZYga > div > article > header > div.o-MQd.z8cbW > div.PQo_0.RqtMr > div.e1e1d > span > a').text

                if username not in prev_user_list:
                    # If we already follow, do not unfollow
                    if webdriver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/header/div[2]/div[1]/div[2]/button').text == 'Follow':
                        
                        webdriver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/header/div[2]/div[1]/div[2]/button').click()
                        
                        new_followed.append(username)
                        followed += 1

                        # Liking the picture
                        button_like = webdriver.find_element_by_css_selector('body > div._2dDPU.CkGkG > div.zZYga > div > article > div.eo2As > section.ltpMr.Slqrh > span.fr66n > button > div > span > svg')
                        button_like.click()
                        likes += 1
                        sleep(randint(10,17))

                        # Comments and tracker
                        comm_prob = randint(1,10)
                        print('{}_{}: {}'.format(hashtag, x,comm_prob))
                        if comm_prob > 7:
                            comments += 1
                            webdriver.find_element_by_css_selector('body > div._2dDPU.CkGkG > div.zZYga > div > article > div.eo2As > section.ltpMr.Slqrh > span._15y0l > button > div > svg').click()
                            comment_box = webdriver.find_element_by_css_selector('body > div._2dDPU.CkGkG > div.zZYga > div > article > div.eo2As > section.sH9wk._JgwE > div > form > textarea')

                            if (comm_prob < 7):
                                comment_box.send_keys('Really cool!')
                                sleep(1)
                            elif (comm_prob > 6) and (comm_prob < 9):
                                comment_box.send_keys('Nice work :)')
                                sleep(1)
                            elif comm_prob == 9:
                                comment_box.send_keys('Nice gallery!!')
                                sleep(1)
                            elif comm_prob == 10:
                                comment_box.send_keys('So cool! :)')
                                sleep(1)
                            # Enter to post comment
                            comment_box.send_keys(Keys.ENTER)
                            sleep(randint(14,20))

                    # Next picture
                    webdriver.find_element_by_link_text('Next').click()
                    sleep(randint(17,21))
                else:
                    webdriver.find_element_by_link_text('Next').click()
                    sleep(randint(12,18))
            # some hashtag stops refreshing photos (it may happen sometimes), it continues to the next
            #except:
            #    continue

        for n in new_followed:
            prev_user_list.append(n)
            
        updated_user_df = pd.DataFrame(prev_user_list, columns=['Usernames'])
        updated_user_df.to_csv(f'{os.getcwd()}/users_followed_list.csv', index=False)
        print(f'Liked {likes} photos.')
        print(f'Commented {comments} photos.')
        print(f'Followed {followed} new people.')
예제 #15
0
# 接受现有警告框
#switch_to.alert.accept()
# 解算现有警告框
#switch_to.alert.dismiss()
# 在警告框中输入文本
#switch_to.alert.send_keys()

from selenium import webdriver as dr
from time import sleep as sl

dr = dr.Chrome()
url = 'https://www.baidu.com/'
dr.get(url)

sl(2)
st = dr.find_element_by_link_text("设置")
st.click()
ss = dr.find_element_by_link_text("搜索设置")
ss.click()
sl(2)

hp = dr.find_element_by_id("sh_2")
hp.click()
sl(2)

#bc = dr.find_element_by_link_text("保存设置")
bc = dr.find_element_by_xpath("//div[@id='gxszButton']/a[1]")
bc.click()
sl(2)

#切换到ALTER弹窗
예제 #16
0
driver.forward()  # 页面前进
driver.set_window_size(540, 960)  # 设置窗口大小,如手机分辨率为540*960
driver.maximize_window()  # 最大化窗口
driver.get_screenshot_as_file("d:\\test\\aa.jpg")  # 截图,定义文件位置名称
# 获取当前window的截图,出现IOError时候返回False,截图成功返回True。
test.img = driver.get_screenshot_as_base64()
driver.close()  # 关闭当前窗口
driver.quit()  # 关闭所有窗口,退出浏览器进程

# 2.2 -------常用18种元素定位------
# 定位单个元素,8种
webdriver.find_element_by_id("")
webdriver.find_element_by_name("")
webdriver.find_element_by_class_name("")
webdriver.find_element_by_tag_name("")
webdriver.find_element_by_link_text("")
webdriver.find_element_by_partial_link_text("")
webdriver.find_element_by_css_selector("")
webdriver.find_element_by_xpath("")
# 定位一组元素,返回对象列表  8种
webdriver.find_elements_by_id("")  # id复数定位
webdriver.find_elements_by_name("")  # name复数定位
webdriver.find_elements_by_class_name("")  # class复数定位
webdriver.find_elements_by_tag_name("")  # teg复数定位
webdriver.find_elements_by_link_text("")  # link复数定位
webdriver.find_elements_by_partial_link_text("")  # partial_link复数定位
webdriver.find_elements_by_css_selector("")  # css_selector 复数定位
webdriver.find_elements_by_xpath("")  # xpath复数定位
# 这两种是参数化的方法,对上面各8种的总结
webdriver.find_element(by='id', value="")
webdriver.find_elements(by='id', value="")
예제 #17
0
                    sleep(2)
                        
                        # Enter to post comment
                    text_enter=comment_box.send_keys(Keys.ENTER)
                    sleep(3)
                    
                    #follow :
                    #follow = webdriver.find_element_by_css_selector("body > div._2dDPU.vCf6V > div.zZYga > div > article > header > div.o-MQd > div.PQo_0 > div.bY2yH > button")
                    #follow.click()
                    #sleep(1)
                    
                    

                # Next picture
                   
                    images_trial = webdriver.find_element_by_link_text('Next').click()
                    print("next image processing")
                    sleep(randint(1,5))
                   
                    #button_2=webdriver.find_element_by_css_selector("body > div._2dDPU.vCf6V > div.zZYga > div > article > div.eo2As > section.ltpMr.Slqrh > span.fr66n > button > span")
                    #button_2.click()
                    
                    
               
        else:
                    webdriver.find_element_by_link_text('Next').click()
                
             
    # some hashtag stops refreshing photos (it may happen sometimes), it continues to the next
    except:
        continue
예제 #18
0
                    sleep(randint(18, 25))
                    comments += 1
                    webdriver.find_element_by_xpath(
                        '/html/body/div[3]/div[2]/div/article/div[2]/section[1]/span[2]/button/span'
                    ).click()
                    comment_box = webdriver.find_element_by_xpath(
                        '/html/body/div[3]/div[2]/div/article/div[2]/section[3]/div/form/textarea'
                    )
                    comment_box.send_keys('Really cool!')
                    sleep(3)

                    # Enter to post comment
                    comment_box.send_keys(Keys.ENTER)
                    sleep(randint(22, 28))
                # Next picture
                webdriver.find_element_by_link_text('Next').click()
                sleep(randint(25, 29))
            else:
                webdriver.find_element_by_link_text('Next').click()
                sleep(randint(20, 26))
                # sleep(2)
    # some hashtag stops refreshing photos (it may happen sometimes), it continues to the next
    except:
        continue

for n in range(0, len(new_followed)):
    prev_user_list.append(new_followed[n])

updated_user_df = pd.DataFrame(prev_user_list)
updated_user_df.to_csv('{}_users_followed_list.csv'.format(
    strftime("%Y%m%d-%H%M%S")))
예제 #19
0
from  selenium import  webdriver
import  time
from  selenium.webdriver import  ActionChains
webdriver=webdriver.Chrome()
webdriver.get("https://www.qcc.com")
webdriver.maximize_window()
time.sleep(3)
webdriver.find_element_by_xpath("//*[@id='addfavorModal']/div/div/div[1]/img[1]").click()
webdriver.find_element_by_link_text("登录 | 注册").click()
time.sleep(6)
huadong=webdriver.find_element_by_xpath("//*[@id='nc_1_n1z']")
#创建Actionchain
ac=ActionChains(webdriver)
#click_and_hold模拟按住鼠标左键在源元素上,点击并且不释放         release()松开鼠标按键
ac.click_and_hold(huadong).move_by_offset(348,0).perform()
time.sleep(6)
webdriver.quit()