我想將for循環的輸出分配給變量或字典,但現在我只能打印出循環的第一個迭代,它是甚至沒有正確的格式。將for循環的輸出分配給一個變量
這裏是我的代碼:
result, data = mail.uid('search', None, "(FROM '[email protected]')") # 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
我想這個輸出是如何執行了這段代碼的格式,但所有這一切的頌歌是打印出來的提取鏈接正確:
result, data = mail.uid('search', None, "(FROM '[email protected]')") # 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.tiffa ny.com/r/YB7DL5S/32FU1/5A6EIF/QFMQOO/T2WUY/52/h"='lucida =「」sans =「」style ='3D「text-decoration:none;' unicode =「>>參與,
'我想這是這個代碼執行的輸出格式'恐怕我真的不明白這行或你想要的格式是什麼。也許你可以展示你想要的實際輸出的例子嗎? –
輸出大約40個用美麗的名字分析的網址,用行 – metersk