Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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 TypeError:str对象不是可调用的请求模块_Python - Fatal编程技术网

Python TypeError:str对象不是可调用的请求模块

Python TypeError:str对象不是可调用的请求模块,python,Python,嘿,伙计们,我刚刚进入了请求模块,我正在尝试寻找一个特定的响应文本,但似乎做不到 我试着用r.text做if\ 错误: C:\Python34\python.exe "C:/Users/Shrekt/PycharmProjects/Python 3/untitleds/gg.py" Traceback (most recent call last): File "C:/Users/Shrekt/PycharmProjects/Python 3/untitleds/gg.py", line 12,

嘿,伙计们,我刚刚进入了请求模块,我正在尝试寻找一个特定的响应文本,但似乎做不到

我试着用
r.text
if
\

错误:

C:\Python34\python.exe "C:/Users/Shrekt/PycharmProjects/Python 3/untitleds/gg.py"
Traceback (most recent call last):
File "C:/Users/Shrekt/PycharmProjects/Python 3/untitleds/gg.py", line 12, in <module>
if r.text("You have") !=-1:
TypeError: 'str' object is not callable

import requests

with requests.session() as s:
login_data = dict(uu='Wowsxx', pp='blahpassword', sitem='LIMITEDQTY')

#cookie = s.cookies['']

s.post('http://lqs.aq.com/login-ajax.asp', data=login_data, headers={"Host": "lqs.aq.com", "User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0", "Referer": "http://lqs.aq.com/default.asp", "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"})

r = s.get('http://lqs.aq.com/limited.asp')

if r.text("You have") !=-1:
    print("found")
C:\Python34\python.exe“C:/Users/Shrekt/PycharmProjects/python3/untitleds/gg.py”
回溯(最近一次呼叫最后一次):
文件“C:/Users/Shrekt/PycharmProjects/Python 3/untitleds/gg.py”,第12行,在
如果r.text(“您有”)=-1:
TypeError:“str”对象不可调用
导入请求
将requests.session()作为s:
login\u data=dict(uu='Wowsxx',pp='blahpassword',sitem='LIMITEDQTY')
#cookie=s.cookies[“”]
s、 邮政('http://lqs.aq.com/login-ajax.asp,data=login_data,headers={“Host”:“lqs.aq.com”,“用户代理”:“Mozilla/5.0(Windows NT 6.2;WOW64;rv:31.0)Gecko/20100101 Firefox/31.0”,“Referer”:”http://lqs.aq.com/default.asp,“内容类型”:“应用程序/x-www-form-urlencoded;字符集=UTF-8”})
r=s.get('http://lqs.aq.com/limited.asp')
如果r.text(“您有”)=-1:
打印(“找到”)
这不是检查
r.text
(字符串)是否包含或等于某个字符串的正确方法

你需要做什么

if "You have" in r.text:  # Check for substring


看起来您的问题在于行
r.text

如果你看一下的介绍,你会发现
r.text
是一个字符串

你想这样写这行:


如果r.text中的“youhave:

您最有可能想到的是内置函数

返回在s中找到子字符串sub的最低索引 该sub完全包含在s[start:end]中。失败时返回-1。 开始和结束的默认值以及负值的解释为 与切片相同

在这种情况下,你会改变

if r.text("You have") !=-1: // note that text is a string not a function
    print("found")
致:

或者你可以简单地用一种更通俗易懂的形式来写

if "You have" in r.text:
    print("found")

请发布整个回溯
r.text
这不返回文本内容吗?你期望那行代码做什么?我想得到一个特定的响应代码,比如page.find(“这行代码”),但它不起作用谢谢你的帮助兄弟:)
string.find(s, sub[, start[, end]])
if r.text("You have") !=-1: // note that text is a string not a function
    print("found")
if r.text.find("You have") !=-1: // note that text.find is a function not a string! :)
    print("found")
if "You have" in r.text:
    print("found")