为了账号安全,请及时绑定邮箱和手机立即绑定

PyCharm click()点击按钮错误'NoneType' object has no

PyCharm click()点击按钮错误'NoneType' object has no

慕村9548890 2019-04-18 11:15:35
问题描述Python爬虫爬取qq空间,点击“帐号密码登录”按钮(driver.find_element_by_id('switcher_plogin').click())不通过编译,提示AttributeError: 'NoneType' object has no attribute 'click'相关代码# 爬取好友的说说信息# 爬取思路# 先使用selenium登录自己的QQ获取cookies# 将cookies传给requests# 找到所有好友的QQ号# 通过构造url对好友的信息进行爬取import reimport timeimport clickimport pymysqlimport requestsfrom selenium import webdriver# g_tk算法def get_g_tk(cookie):    hashes = 5381    for letter in cookie['p_skey']:        hashes += (hashes << 5) + ord(letter)  # ord()是用来返回字符的ascii码    return hashes & 0x7fffffff# 使用selenium登录def login():    driver = webdriver.chrome    # 打开QQ网页    driver.get("https://qzone.qq.com/")    time.sleep(5)    driver.switch_to_frame('login_frame')    driver.find_element_by_id('switcher_plogin').click()    driver.find_element_by_id('u').clear()    driver.find_element_by_id('u').send_keys('账号')    driver.find_element_by_id('p').clear()    driver.find_element_by_id('p').send_keys('密码')    driver.find_element_by_id('login_button').click()    time.sleep(5)    # 得把Frame的定位换回来,否则可能会出错    driver.switch_to.default_content()    return driver# 存储在mysql数据库中def in_mysql(time, content, conn):    time = str(time)    content = str(content)    sql = "insert into QF_infomation(time,content) VALUES('" + time + "','" + content + "')"    conn.query(sql)错误信息Traceback (most recent call last):  File "C:/Users/YSD/PycharmProjects/QQ_Spider-master/QQzone_spider/QQZONE_spider.py", line 165, in <module>    start()  File "C:/Users/YSD/PycharmProjects/QQ_Spider-master/QQzone_spider/QQZONE_spider.py", line 136, in start    driver = login()  File "C:/Users/YSD/PycharmProjects/QQ_Spider-master/QQzone_spider/QQZONE_spider.py", line 31, in login    driver.find_element_by_id('switcher_plogin').click()AttributeError: 'NoneType' object has no attribute 'click'
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1871 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信