python TypeError:'str'对象不是可呼叫的beautifulsoup

a7qyws3x  于 2022-10-30  发布在  Python
关注(0)|答案(1)|浏览(156)

我有这段代码,用beautifulsoup来抓取facebook,但是在'str'部分有一个错误。我读到python读这个像是一个变量,应该是一个函数。但是我还是不明白这一点。

from  selenium import webdriver
from selenium.webdriver.chrome.options import Options
from bs4 import BeautifulSoup
import time
import re
import json
import pandas as pd
from account_credentails import username, password

class Post_Scraper:
    """
    Post_Scraper class allows to scrape Facebook Posts based on search queries.
    """
    LOGIN_URL = "https://www.facebook.com"
    REACTIONS_NAMES = ['Like', 'Angry', 'Love', 'Haha', 'Sad','Care', 'Wow']

    def __init__(self, driver_path, posts_url) -> None:
        driver_path=driver_path('C:\Program Files\Python 3.9\chromedriver.exe')
        self.driver = webdriver.Chrome(driver_path=driver_path)
        self.posts_url = posts_url.replace("www", "mbasic")

    def login(self, username, password) -> None:
        """
        Login to a Facebook Account.

        Args:
            username ('str'))
                Facebook account username/email
            password ('str')
                Facebook account password    
        """
        self.driver.get(self.LOGIN_URL)
        time.sleep(2)
        email_ = self.driver.find_element_by_name("email")
        pass_ = self.driver.find_element_by_name("pass")
        email_.send_keys(username)
        time.sleep(1)
        pass_.send_keys(password)
        time.sleep(2)
        email_.submit()
        time.sleep(10)

我收到类似于"TypeError:'str'对象不可调用',那么我应该怎么做呢?

zpgglvta

zpgglvta1#

如果你分享哪一行可能会更容易弄清楚但是根据this thread about the same error message
......表明如果你在运行脚本之前定义了一个名为str的变量,那么python会认为你在引用这个变量,并想知道你为什么要调用一个变量
所以如果您在错误中添加

str = None # in case str HASN'T been defined...
del str

在引起错误的那一行之前的某处。

相关问题