请选择 进入手机版 | 继续访问电脑版

 找回密码
 立即注册
搜索
热搜: Excel discuz
查看: 1557|回复: 1

[项目代码] 模拟登陆电影网,并领取积分

[复制链接]

482

主题

7万

元宝

75万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
750844
发表于 2021-8-16 21:31:17 | 显示全部楼层 |阅读模式
模拟登陆电影网,然后自动领取积分,登陆环节会停留10秒,人工手动验证。我也不会用Python来领取积分,只是为了学习测试写这个代码。
  1. # 导包
  2. from selenium import webdriver
  3. import time
  4. import requests
  5. from lxml import etree
  6. # 获取[浏览器]的实例化对象
  7. 浏览器对象 = webdriver.Chrome()
  8. 浏览器对象.maximize_window()
  9. # 使用浏览器打开网址
  10. 浏览器对象.get("https://club.ccmnn.com/")
  11. # 定位并输入用户名
  12. 账号 = input('请输入账号:')
  13. 用户名 = 浏览器对象.find_element_by_id('ls_username')
  14. 用户名.clear()
  15. 用户名.send_keys(账号)
  16. # 定位并输入密码  id是唯一的
  17. mima = input('请输入密码:')
  18. 密码 = 浏览器对象.find_element_by_id('ls_password')
  19. 密码.clear()
  20. 密码.send_keys(mima)
  21. # 定位登录按钮并点击
  22. 登录 = 浏览器对象.find_element_by_xpath("//*[@id='lsform']/div/div[1]/table/tbody/tr[2]/td[3]/button/em")
  23. time.sleep(2)
  24. 登录.click()
  25. # 停留10秒钟,人工验证
  26. time.sleep(10)
  27. url = 浏览器对象.current_url
  28. ua = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0"}
  29. cookies = 浏览器对象.get_cookies()
  30. cookies_dict= {}
  31. for i in cookies:
  32.     cookies_dict[i['name']] = i['value']
  33. respon = requests.get(url=url,headers = ua,cookies=cookies_dict).text
  34. jiexi = etree.HTML(respon)
  35. jifen = jiexi.xpath('//*[@id="extcreditmenu"]/font/text()')
  36. 浏览器对象.get("https://club.ccmnn.com/plugin.php?id=hux_miner:hux_miner")
  37. shuaxin = 浏览器对象.find_element_by_id('shouyi_re')
  38. #一定要停留片刻,不然总报错
  39. time.sleep(2)
  40. shuaxin.click()
  41. time.sleep(2)
  42. lingqu = 浏览器对象.find_element_by_id('shouyi_show')
  43. time.sleep(2)
  44. lingqu.click()
  45. time.sleep(2)
  46. 浏览器对象.find_element_by_id('fwin_dialog_close').click()
复制代码




回复

使用道具 举报

482

主题

7万

元宝

75万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
750844
 楼主| 发表于 2021-8-16 21:31:57 | 显示全部楼层
本文,主要知识点,是登陆后获取cookies,并用cookies请求其他页面,进行操作
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|五花八门论坛 ( 豫ICP备15031300号-3 )

GMT+8, 2024-3-29 23:04 , Processed in 0.090983 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表