Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x “str”对象在BeautifulSoup4中没有属性“text”_Python 3.x_Beautifulsoup_Python Requests - Fatal编程技术网

Python 3.x “str”对象在BeautifulSoup4中没有属性“text”

Python 3.x “str”对象在BeautifulSoup4中没有属性“text”,python-3.x,beautifulsoup,python-requests,Python 3.x,Beautifulsoup,Python Requests,为了实现自动化,我正在尝试使用python请求登录到一个网站。我得到一个错误,因为'str'对象没有'text'属性 我的代码是 from BeautifulSoup import BeautifulSoup logging.basicConfig(filename='app.log',level=logging.INFO) headers = { 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (

为了实现自动化,我正在尝试使用python请求登录到一个网站。我得到一个错误,因为'str'对象没有'text'属性

我的代码是

from BeautifulSoup import BeautifulSoup



logging.basicConfig(filename='app.log',level=logging.INFO)
headers = {
    'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
def post_request_curl(data):
    try:   
           with requests.Session() as s:
              login_data=data['login_details']
              r = s.get(url=data['url'], headers=headers)
              soup = BeautifulSoup(r.content, 'html.parser')
              login_data['form_build_id'] = soup.find_all('input', attrs={'name': 'form_build_id'})['value']
              r = s.post(url=data['url'], data=login_data, headers=headers)

              return r  
    except Exception as e:
        logging.error('Error occurred ' + str(e))
尝试:


请添加完整的代码。我已经在哪一行发布了所有的代码错误?是的。我没有看到任何.textsoup=BeautifulSoupr.content,'html.parser'错误发生在HTTPConnectionPoolhost='http',port=80:url://dummy.restapiexample.com/api/v1/create引起的NewConnectionError:无法建立新连接:[Errno-2]名称或服务未知',这里发生的事情是codechef.com服务器拒绝您的连接。您在短时间内从同一ip地址发送了太多请求。请参考我需要在任何站点中使用curl实现此登录。你能推荐一种方法吗?图书馆能帮你吗?
from bs4 import BeautifulSoup
import requests

logging.basicConfig(filename='app.log',level=logging.INFO)
headers = {
    'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
def post_request_curl(data):
    try:   
           with requests.Session() as s:
              login_data=data['login_details']
              r = s.get(url=data['url'], headers=headers)
              soup = BeautifulSoup(r.content, 'html.parser')
              login_data['form_build_id'] = soup.find_all('input', attrs={'name': 'form_build_id'})['value']
              r = s.post(url=data['url'], data=login_data, headers=headers)

              return r  
    except Exception as e:
        logging.error('Error occurred ' + str(e))