| | |
| | | print(e) |
| | | |
| | | |
| | | def login_xhs(): |
| | | while True: |
| | | try: |
| | | browser = ChromiumOptions().auto_port() |
| | | page = ChromiumPage(browser) |
| | | page.set.window.size(int(1920 / 1.2), int(1080 / 1.2)) |
| | | user_agent = random_user_agent.get_random_user_agent() |
| | | page.set.user_agent(ua=user_agent) |
| | | page.get('https://www.xiaohongshu.com/explore') |
| | | if login_button:=page.ele('css:span.reds-button-new-text > span.login-btn'): |
| | | login_button.click() |
| | | while True: |
| | | if me_button:=page.ele("xpath://li[contains(@class, 'user')]//span[@class='channel' and text()='我']"): |
| | | me_button.click() |
| | | cookie_dict = page.cookies(as_dict=True) |
| | | if nickname := page.ele("xpath://div[@class='user-name']"): |
| | | nickname = nickname.text |
| | | if unique_no := page.ele("xpath://div[@class='user-content']/span"): |
| | | unique_no = unique_no.text |
| | | cookie = Cookie( |
| | | nickname=nickname if nickname else None, |
| | | unique_no=unique_no, |
| | | type='user', |
| | | platform='XHS', |
| | | domain='.xiaohongshu.com', |
| | | cookie=json.dumps(cookie_dict), |
| | | user_agent=user_agent, |
| | | is_valid=True, |
| | | # 在此更改租户 |
| | | tenant_id=1, |
| | | |
| | | ) |
| | | add_cookie(cookie) |
| | | page.close() |
| | | break |
| | | time.sleep(1) |
| | | except Exception as e: |
| | | print(e) |
| | | |
| | | |
| | | def login_ks(): |
| | | while True: |
| | | try: |
| | |
| | | if __name__ == '__main__': |
| | | thread_dy = threading.Thread(target=login_dy) |
| | | thread_ks = threading.Thread(target=login_ks) |
| | | thread_xhs= threading.Thread(target=login_xhs) |
| | | # thread_dy2 = threading.Thread(target=login_dy) |
| | | # thread_ks2 = threading.Thread(target=login_ks) |
| | | |
| | | # 启动线程 |
| | | thread_dy.start() |
| | | thread_ks.start() |
| | | thread_xhs.start() |
| | | # thread_dy2.start() |
| | | # thread_ks2.start() |
| | | |
| | | # 等待线程完成 |
| | | thread_dy.join() |
| | | thread_ks.join() |
| | | thread_xhs.join() |
| | | # thread_dy2.join() |
| | | # thread_ks2.join() |
| | | # |