当前位置:网站首页>Chattering tiktok tutorial, simple data collection, rookie must see

Chattering tiktok tutorial, simple data collection, rookie must see

2020-12-08 10:47:22 TiToData

Tiktok App What is used interactively with the server HTTPS agreement , Use Fiddler It's easy to capture data , As shown in the figure below .
image.png
But it's not so easy to simulate a valid request yourself , Because it uses a signature mechanism , In all requests as and cp Two signature parameters , We cannot construct a valid request unless we know the signature algorithm .
Here we use tiktok. App The way , Give Way App Make a valid request for us , Then we intercept the server's HTTP Response data , And then extract the information we are interested in .
The following is a practical case to introduce the whole process , According to the needs of customers , We need to collect some system recommendations after the specified user has added and disabled “ You may be interested in ” The data of ( As shown in the figure below ) For commodity marketing .
image.png
Click on “ To view more ” You can see more system recommended user list data , As shown in the figure below .
image.png
We simulate the operation as follows App:
1. Tiktok .
2. Click the search button .
3. Enter search keywords ( Tiktok user ID), Click on the search .
4. Matching users found , Click to follow .
5. Click system recommendation “ To view more ”, Simulate sliding the screen up many times , Until the data is loaded ( The screen appears “ No more for the time being ”).
At the same time , We use capture scripts ( have access to Fiddler Of Customize Rules, You can also use Mitmproxy), Capture and filter URL contains /user/recommend/ Of HTTP Response data , from JSON The user information recommended by the system is extracted from the data ( As shown in the figure below ).
Tiktok App The script core code for is shown below :
view plaincopy to clipboardprint?

from com.dtmilano.android.viewclient import ViewClient


def search_douyin_for_recommend_user(douyin_id):


#  Tiktok data collection for designated voice accounts 


#  Connecting equipment 
serialno = None
if serialno:
    os.system('adbconnect{}'.format(serialno or ''))
    time.sleep(3)
    device, serialno = ViewClient.connectToDeviceOrExit(serialno=serialno)
    vc = ViewClient(device, serialno, autodump=False)

    #  Tiktok   
    log(u' Tiktok .')
    device.shell('am force-stop com.ss.android.ugc.aweme')
    time.sleep(2)

    #  Tiktok   
    log(u' Tiktok .')
    device.shell('am start -n com.ss.android.ugc.aweme/.main.MainActivity')
    time.sleep(5)
    #  Pause the video   
    log(u' Click on the screen , Pause the video .')
    device.touch(514, 1048)

    #  Click the search button   
    vc.dump()
    search_btn = vc.findViewById('com.ss.android.ugc.aweme:id/amj')
    if search_btn:
        log(u' Click the search button , Jump to the search page .')
        search_btn.touch()

        vc.dump()
        #  Click on the search input box   
        search_input = vc.findViewById('com.ss.android.ugc.aweme:id/ad_')
        if search_input:
            log(u' Click on the search box , Ready to enter keywords .')
            search_input.touch()

            #  Input tiktok ID  
            log(u' Enter search keywords : {}.'.format(douyin_id))
            device.type(douyin_id.encode('UTF-8'))

            #  Click the search button   
            search_btn = vc.findViewById('com.ss.android.ugc.aweme:id/cp8')
            if search_btn:
                log(u' Submit search .')
                search_btn.touch()
                time.sleep(2)
                vc.dump()

                ##  Switch to user   
                # user_tab = vc.findViewWithText(u' user ')  
                # user_tab.touch()  

                #  Find a match   
                matches = []


                def find_matches(view):
                    if view.getClass() == 'android.widget.TextView':
                        text = view.getText()
                        if douyin_id.lower() in text.lower():
                            #  We found a match   
                            log(u' Find a match : {}'.format(text))
                            matches.append(view)
                        else:
                            # print text  
                            pass


                vc.traverse(transform=lambda view: find_matches(view))
                if matches:
                    #  Is there a followed button   
                    btn = vc.findViewWithText(u' Followed ')
                    if btn:
                        #  Cancel attention first   
                        log(u' I've seen it before , Cancel attention first .')
                        btn.touch()
                        time.sleep(1)
                    user_matched = matches[0]
                    log(u' Click to enter personal homepage .')
                    user_matched.touch()
                    time.sleep(1)

                    #  Focus   
                    vc.dump()
                    follow_btn = vc.findViewById('com.ss.android.ugc.aweme:id/aei')
                    if follow_btn:
                        #  Click to follow   
                        log(u' Click to follow ')
                        follow_btn.touch()
                        time.sleep(1)
                        #  Click to see more   
                        vc.dump()
                        viewmore_btn = vc.findViewById('com.ss.android.ugc.aweme:id/bqn')
                        if viewmore_btn:
                            #  Click to see more   
                            log(u' Click to see more system recommendations ')
                            viewmore_btn.touch()
                            time.sleep(1)
                            i = 0
                            while True:
                                #  Slide up   
                                device.drag((345, 1762), (345, 550), duration=100)
                                log(u' Slide up to load more ')
                                i += 1
                                if i % 5 == 0:
                                    #  Drag the 10 To see if there are more   
                                    vc.dump()
                                    if vc.findViewWithText(u' No more for the time being '):
                                        log(u' No more for the time being , "{}" The recommended data collection is completed .'.format(douyin_id))
                                        #  The acquisition was successful   
                                        return True
                                    failed_tip = vc.findViewWithText(u' Loading failed , Click Retry ')
                                    if failed_tip:
                                        log(u' Loading failed , Click Retry .')
                                        failed_tip.touch()
                        else:
                            #  The view more button was not found   
                            log(u' The view more button was not found ')
                    else:
                        #  No follow button found   
                        log(u' No follow button found ')
                else:
                    #  No matching users were found   
                    log(u' No matching users were found ')
            else:
                #  Search submit button not found   
                log(u' Search submit button not found .')
        else:
            #  Search input box not found   
            log(u' Search input box not found .')
    else:
        #  Search button not found   
        log(u' Search button not found .')

The running screenshot of the above script is shown below :
image.png
Finally, some sample data are attached :image.png


——————————————————————————————————————————

TiToData: Professional short video 、 Live data interface service platform .

For more information, please contact : TiToData

Covering mainstream platforms : Tiktok , Well quickly , The little red book ,TikTok,YouTube

——————————————————————————————————————————

TiToData: Professional short video 、 Live data interface service platform .

For more information, please contact : TiToData

Covering mainstream platforms : Tiktok , Well quickly , The little red book ,TikTok,YouTube

版权声明
本文为[TiToData]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201208104656089m.html