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

问题描述

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 re

import time

import click

import pymysql

import requests

from 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'


慕村9548890
浏览 1872回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python