How to get all data in page with a Python HTTP request

Viewed 36

I wrote a simple function to get the data from this page that looks like so:

def getTrendingHashTags(self, params=None, headers=None):
        url = "https://ads.tiktok.com/business/creativecenter/inspiration/popular/hashtag/pc/en?from=001119"
        try:
            response = requests.get(url, params=params, headers=headers)
        except Exception as e:  
            raise e
        return response 

I get a correct response (200), but only the top three hashtags are returned, not the 100 on the page [without logging in, we can only see the top three, but after logging in, the top 100 are available].

{"1": {"hashtagId": "682333", "hashtagName": "682333", "creators": {"creator": [{"nickName": "SUPES", "avatwarUrl": "https://p16-sign-va.tiktokcdn.com/tos-maliva-avt-0068/4b7d46606322922a217f568bb830b65c~c5_100x100.png?x-expires=1663124400&x-signature=mQ9756hutT%2BnQSNnF1fhyM%2BPpJs%3D"}, {"nickName": "De todo un Paco", "avatarUrl": "https://p16-sign-va.tiktokcdn.com/musically-maliva-obj/1667606568576006~c5_100x100.png?x-expires=1663124400&x-signature=rSYVk5etTcOC41qwZnqEsWojWCI%3D"}, {"nickName": "Natalia Sisik", "avatarUrl": "https://p77-sign-sg.tiktokcdn.com/aweme/100x100/tiktok-obj/2253f14fba8a58e3ed45373188d769be.png?x-expires=1663124400&x-signature=CNqiQOYBVYqX7b6uldpRDbZrpiM%3D"}]}}, "2": {"hashtagId": "58640166", "hashtagName": "58640166", "creators": {"creator": [{"nickName": "Young Hollywood", "avatarUrl": "https://p16-sign-va.tiktokcdn.com/tos-maliva-avt-0068/ce18a4dca5adb161c47173e638cb453c~c5_100x100.png?x-expires=1663124400&x-signature=XqafMQIi2sv%2FExJ8YLdy%2BmUK8Oc%3D"}, {"nickName": "JAGMAC", "avatarUrl": "https://p16-sign-va.tiktokcdn.com/tos-maliva-avt-0068/efc1afc7f2b33f2c106a7a21e89c170b~c5_100x100.png?x-expires=1663124400&x-signature=x5g1%2BbuLw8QEIqzHsLcGdZZYHXY%3D"}, {"nickName": "anasnonofficiel \ud83d\ude0e", "avatarUrl": "https://p16-sign-va.tiktokcdn.com/tos-maliva-avt-0068/5cb422d40fdaafa485c486dc9d120011~c5_100x100.png?x-expires=1663124400&x-signature=0E0jFTQ7ZHULcz5pgNaA3tMDDYE%3D"}]}}, "3": {"hashtagId": "270448", "hashtagName": "270448", "creators": {"creator": [{"nickName": "Dylan Mulvaney", "avatarUrl": "https://p16-sign-va.tiktokcdn.com/tos-maliva-avt-0068/524846e03ece30994f98dec1bf35bb5a~c5_100x100.png?x-expires=1663124400&x-signature=XNUhzOddVe6hySlRQLM0tukQKn8%3D"}, {"nickName": "Lani Baker Randol", "avatarUrl": "https://p16-sign-va.tiktokcdn.com/tos-maliva-avt-0068/11f565e960ff3d489f6798c8fee87adf~c5_100x100.png?x-expires=1663124400&x-signature=Q1FWTox1l%2FpxMcddFEBFOLDxfIk%3D"}, {"nickName": "Brooke Barry", "avatarUrl": "https://p16-sign-va.tiktokcdn.com/tos-maliva-avt-0068/21011fae8821373c332c3cf49cd4209e~c5_100x100.png?x-expires=1663124400&x-signature=uoCf%2Bp1k1HMeQD0BxYyhWb51GTY%3D"}]}}}

Would I need to change the header information, etc. to log into the page with my credentials to be able to get the top 100, rather than only the top 3? After logging in, the url changes to

https://ads.tiktok.com/business/creativecenter/inspiration/popular/hashtag/pc/en?from=001119&is_new_connect=0&is_new_user=0

but if I try this in the request url, I get the exact same response. There is a captcha that needs to be done, and a verification code that is sent to my email when I log in, would this be the reason I am only able to see the top three? Is there a straightforward way of getting all the info from the above function?

All info is super appreciated. Thanks!

0 Answers
Related