使用此代码,我从 BS 解析中获得以下 URL:
result, data = mail.uid('search', None, "(FROM 'tiffany@e.tiffany.com')") # search and return uids instead
latest_email_uid = data[0].split()[-1]
result, data = mail.uid('fetch', latest_email_uid, '(RFC822)')
raw_email = data[0][1]
html = raw_email
soup = BS(html)
urls=[]
for x in soup.find_all('a', href=True):
urls.append(x['href'])
print urls
输出
'3D"http://elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/6EN2U/52/h"='
如何去除前 4 个和后 3 个字符?这是我可以在漂亮的汤中做的事情还是应该使用 split()?