正则findall 错误,refindall 怎么是一个元祖?不是列表吗

value = re.findall(r'.*?<Cookie\s*k=(.*?)\s*for.*?<Cookie tk=(.*?)\s+',

str(self.s.get("http://e.oppomobile.com/cpdStat/trend", headers=self.headers).cookies))

print value

tk_value = value[1]

k_value = value[0]

<RequestsCookieJar[<Cookie k=fbcff86069a9436aadc36c2e93874b7f for e.oppomobile.com/>, <Cookie tk=ed9c66d3fe909612a7e659e82ad5ae5b for e.oppomobile.com/>]>

[('154c145a66d448d4b931693ad5585d55', '281e9d81706f3d1d39dc7037b4ffa048')]

Traceback (most recent call last):

File "/home/stephen/PycharmProjects/Oppo/oppo.py", line 348, in <module>

oppo.login_in()

File "/home/stephen/PycharmProjects/Oppo/oppo.py", line 72, in login_in

self.Promotion_manage(manage_page_response.encode("utf-8"))

File "/home/stephen/PycharmProjects/Oppo/oppo.py", line 276, in Promotion_manage

self.report_list(manage_page_data[i-10+2-1])

File "/home/stephen/PycharmProjects/Oppo/oppo.py", line 287, in report_list

tk_value = value[1]

IndexError: list index out of range

图片描述

回答:

cookies取值不需要通过正则,你直接使用索引就行了
比如你的cookies取tk值

self.s.cookies['tk']

回答:

获取cookie的方法楼上已经说了,关于正则,你这里使用了两个分组,就是(.*?)所以列表里的每个元素是两个分组匹配结果构成的元组

回答:

re.findall 怎么是一个列表?不是元组吗?

以上是 正则findall 错误,refindall 怎么是一个元祖?不是列表吗 的全部内容, 来源链接: utcz.com/a/157386.html

回到顶部