python爬虫爬网络数据_使用 Python 爬虫爬取网络

#!/usr/bin/python#coding=utf-8

importsmtplibimportoptparsefrom email.mime.text importMIMETextfrom twitterClass import *

from random importchoicedefsendMail(user, pwd, to, subject, text):

msg=MIMEText(text)

msg['From'] =user

msg['To'] =to

msg['Subject'] =subjecttry:

smtpServer= smtplib.SMTP('smtp.gmail.com', 587)print "[+] Connecting To Mail Server."smtpServer.ehlo()print "[+] Starting Encrypted Session."smtpServer.starttls()

smtpServer.ehlo()print "[+] Logging Into Mail Server."smtpServer.login(user, pwd)print "[+] Sending Mail."smtpServer.sendmail(user, to, msg.as_string())

smtpServer.close()print "[+] Mail Sent Successfully."

except:print "[-] Sending Mail Failed."

defmain():

parser= optparse.OptionParser('[*]Usage: python sendSam.py -u -t ' + '-l -p ')

parser.add_option('-u', dest='handle', type='string', help='specify twitter handle')

parser.add_option('-t', dest='tgt', type='string', help='specify target email')

parser.add_option('-l', dest='user', type='string', help='specify gmail login')

parser.add_option('-p', dest='pwd', type='string', help='specify gmail password')

(options, args)=parser.parse_args()

handle=options.handle

tgt=options.tgt

user=options.user

pwd=options.pwdif handle == None or tgt == None or user ==None or pwd==None:printparser.usage

exit(0)print "[+] Fetching tweets from:" +str(handle)

spamTgt=reconPerson(handle)

spamTgt.get_tweets()print "[+] Fetching interests from:" +str(handle)

interests=spamTgt.find_interests()print "[+] Fetching location information from:" +str(handle)

location= spamTgt.twitter_locate('mlb-cities.txt')

spamMsg= "Dear" + tgt + ","

if (location !=None):

randLoc=choice(location)

spamMsg+= "Its me from" + randLoc + "."

if (interests['users'] !=None):

randUser= choice(interests['users'])

spamMsg+= " " + randUser + "said to say hello."

if (interests['hashtags'] !=None):

randHash=choice(interests['hashtags'])

spamMsg+= "Did you see all the fuss about" + randHash + "?"

if (interests['links']!=None):

randLink=choice(interests['links'])

spamMsg+= "I really liked your link to:" + randLink + "."spamMsg+= "Check out my link to http://evil.tgt/malware"

print "[+] Sending Msg:" +spamMsg

sendMail(user, pwd, tgt,'Re: Important', spamMsg)if __name__ == '__main__':

main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值