gpt4 book ai didi

python - 正则表达式捕获html隐藏输入

转载 作者:行者123 更新时间:2023-11-30 23:33:07 25 4
gpt4 key购买 nike

我试图用 python pycurl 捕获 joomla token ,我写这个功能代码:

import urllib, urllib2, sys, re
import cStringIO
import pycurl

def CaptureToken(cURL):
buf = cStringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL, cURL)
c.setopt(c.WRITEFUNCTION, buf.write)
c.setopt(c.CONNECTTIMEOUT, 30)
c.setopt(c.TIMEOUT, 30)
c.perform()
html = buf.getvalue()
buf.close()
results = re.match(r"(type=\"hidden\" name=\"([0-9a-f]{32})\")", html).group(1)
print results

CaptureToken('http://www.proregionisbono.org.pl/administrator/index.php')

在 Notepad++ 中这个正则表达式工作正常,在python中不起作用:(,请有人帮助我。

最佳答案

re.match 从字符串的开头匹配,您可能需要 re.search 它将匹配字符串中的任何位置。

Python docs

您的代码的这个版本适合我:

import urllib, urllib2, sys, re
import cStringIO
import pycurl

def CaptureToken(cURL):
buf = cStringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL, cURL)
c.setopt(c.WRITEFUNCTION, buf.write)
c.setopt(c.CONNECTTIMEOUT, 30)
c.setopt(c.TIMEOUT, 30)
c.perform()
html = buf.getvalue()
buf.close()
results = re.search(r'(type="hidden" name="([0-9a-f]{32})")', html).group(2)
print results

CaptureToken('http://www.proregionisbono.org.pl/administrator/index.php')

关于python - 正则表达式捕获html隐藏输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19103555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com