从 - BeautifulSoup python中提取字符串

问题描述 投票:0回答:1

我正在尝试创建一个python脚本来从Webmail中提取一些信息。我想按照重定向。

我的代码:

br1 = mechanize.Browser()
br1.set_handle_robots(False)
br1.set_cookiejar(cj)
br1.open("LOGIN URL")
br1.select_form(nr=0)
br1.form['username'] = mail_site
br1.form['password'] = pw_site
res1 = br1.submit()
html = res1.read()

print html

结果不是我所期望的。它仅包含重定向脚本。我已经看到我必须从此脚本中提取信息以遵循此重定向。所以,就我而言,我要将jsessionid提取到一个脚本中。

该脚本是:

<script>
    function redir(){      
window.self.location.replace('/webmail/en_EN/continue.html;jsessionid=1D5QS4DA6C148DC4C14QS4CS5.1FDS5F4DSV1A64DA5DA?MESSAGE=NO_COOKIE&DT=1&URL_VALID=welcome.html');
return true;
}
</script>

如果我没错,我要建立一个正则表达式。我尝试过很多东西,但没有结果。

有人有想法吗?

python regex beautifulsoup
1个回答
0
投票
import re
get_jsession = re.search(r'jsessionid=([A-Za-z0-9.]+)',script_)
print(get_jsession.group(1))
>>> '1D5QS4DA6C148DC4C14QS4CS5.1FDS5F4DSV1A64DA5DA'
© www.soinside.com 2019 - 2024. All rights reserved.