我正在尝试将 for 循环的输出分配给变量或字典,但到目前为止,我只能让它打印循环的第一次迭代,而且它的格式甚至都不正确。
这是我的代码:
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)
pretty_email = soup.prettify('utf-8')
urls={}
for x in soup.find_all('a', href=True):
urls['href'] = x
print urls
我希望这个输出的格式是这个代码的执行方式,但是所有这些 odes 都是正确打印出提取的链接:
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)
pretty_email = soup.prettify('utf-8')
for urls in soup.find_all('a', href=True):
print urls['href']
print urls
谢谢!
编辑:
我希望它打印的方式是这样的:
3D"http://elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/9SUZ8/52/h"=
3D"http://elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/N8ASK/52/h"=
3D"http://elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/DNH42/52/h"=
3D"http://elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/T2WPJ/52/h"=
3D"http://elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/PO7RQ/52/h"=
3D"http://elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/BRLMA/52/h"=
3D"http://elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/N8ASQ/52/h"=
3D"http://elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/SV4PN/52/h"=
3D"http://elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/RC53N/52/h"=
3D"http://elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/7Q3AA/52/h"=
通过下面的解决方案,我得到了这个:
http://elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/1XF33/52/h?='n:underline="" style='3D"text-decoratio='>点击这里,http: //elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/6EN2U/52/h"='target='3D"_blank"'>http://eimg.tiffany.com/mbs_tiffanyc/Standard/Logoblue .gif"' title='3D"Tiffany' wi="dth=3D147"/>, http://elink.tiffany.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/T2WUY/52/h"=' lucida ="" sans="" style='3D"文本装饰:无;' unicode="">订婚,