问题描述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'
添加回答
举报
0/150
提交
取消