forked from Mr9esx/Nyspider
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import requests | ||
from bs4 import BeautifulSoup | ||
import time | ||
import re | ||
import json | ||
|
||
headers = { | ||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", | ||
"Accept-Encoding": "gzip, deflate", | ||
"Accept-Language": "en-US,en;q=0.5", | ||
"Connection": "keep-alive", | ||
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0"} | ||
|
||
|
||
email_template=open('email_template','r',encoding='utf-8').read() | ||
|
||
def login(): | ||
session=requests.session() | ||
data={ | ||
'login':"", | ||
'password':"", | ||
'remember':"1" | ||
} | ||
session.post('http://members.brokerbin.com/',data=data,headers=headers,timeout=30) | ||
return session | ||
|
||
def get_form(session): | ||
platform='CISCO' | ||
html=session.get('http://members.brokerbin.com/main.php?platform={}&refresh=%27.%24submit.%27&loc=top100&view=1'.format(platform),headers=headers,timeout=30).text | ||
table=BeautifulSoup(html,'html.parser').find('table',{'class':'rowHighlight'}).find_all('tr',{'class':'pref_vendor'}) | ||
result=[] | ||
for item in table: | ||
try: | ||
url='http://members.brokerbin.com/'+item.find('a').get('href') | ||
result.append(url) | ||
except: | ||
continue | ||
return result | ||
|
||
def get_person(session,url): | ||
html=session.get(url,headers=headers,timeout=30).text | ||
table=BeautifulSoup(html,'html.parser').find('table',{'class':'nowrap'}).find_all('tr',{'class':'caution'}) | ||
result=[] | ||
for item in table: | ||
try: | ||
tds=item.find_all('td') | ||
if 'Hrs' not in tds[1].get_text(): | ||
continue | ||
product=tds[2].get_text().replace('\t','').replace(' ','').replace('\xa0','') | ||
person_name=item.find('a').get_text() | ||
person_url=re.findall("newWindow\('(.*?),\d",item.find('a').get('onclick'))[0] | ||
result.append({'product_name':product,'person_name':person_name,'person_url':person_url}) | ||
except: | ||
continue | ||
return result | ||
|
||
def get_email(session,url): | ||
html=session.get('http://members.brokerbin.com/'+url,headers=headers,timeout=30).text | ||
email=re.findall('"mailto:(.*?)"',html)[0] | ||
return email | ||
|
||
def get_price(product_name): | ||
html=requests.get('http://sailnetwork-cc.3dcartstores.com/search_quick.asp?q='+product_name,headers=headers,timeout=30).text | ||
data=json.loads(html)[0]['results'] | ||
for item in data: | ||
if item[1]==product_name: | ||
return item | ||
return data[0] | ||
|
||
def write_to_email_txt(item): | ||
text=email_template.format(name=item['person_name'],product_name=item['product_name'] | ||
,price=item['product'][3],product_url='http://sailnetwork-cc.3dcartstores.com/'+item['product'][0]) | ||
date=time.strftime('%Y%m%d') | ||
f=open(date+'.txt','a',encoding='utf-8') | ||
f.write('qoute for %s\r\n'%(item['product_name'])+'***'*4+'\r\n'+item['email']+'\r\n'+'***'*4+'\r\n'+text+'\r\n'+'---'*8+'\r\n\r\n') | ||
f.close() | ||
|
||
def main(): | ||
session=login() | ||
urls=get_form(session) | ||
persons=[] | ||
for url in urls: | ||
result=get_person(session,url) | ||
persons+=result | ||
print(url,'ok') | ||
result=[] | ||
price={} | ||
for person in persons: | ||
try: | ||
email=get_email(session,person['person_url']) | ||
except: | ||
continue | ||
person['email']=email | ||
try: | ||
product_price=price[person['product_name']] | ||
person['product']=product_price | ||
write_to_email_txt(person) | ||
except: | ||
print(person['product_name'],'get price failed') | ||
failed=open('failed','a',encoding='utf-8') | ||
failed.write(str(person)+'\r\n') | ||
failed.close() | ||
continue | ||
pass | ||
try: | ||
product_price=get_price(person['product_name']) | ||
except: | ||
print(person['product_name'],'get price failed') | ||
failed=open('failed','a',encoding='utf-8') | ||
failed.write(str(person)+'\r\n') | ||
failed.close() | ||
continue | ||
price[person['product_name']]=product_price | ||
person['product']=product_price | ||
write_to_email_txt(person) | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
</head> | ||
<body> | ||
<h3> | ||
Hi {name}, | ||
</h3> | ||
<p> | ||
We have following quote matches your "searching" on Brokerbin: | ||
</p> | ||
<p> | ||
{product_name} new landed {price} each 3days delievery | ||
</p> | ||
<p> | ||
<a href="{product_url}"> | ||
Click here to buy on our website. | ||
</a> | ||
</p> | ||
<p> | ||
Please know the special price only provide after you logined. | ||
</p> | ||
<p> | ||
Thanks! | ||
</p> | ||
<p> | ||
</p> | ||
<p> | ||
-- | ||
</p> | ||
<p> | ||
*Please register at our web-store:www.sailnetwork.com to check P&A 24-7. Regular coupons will be sent to register customers, and product prices will be lower online. | ||
<br> | ||
Best regards; | ||
<br> | ||
Sales Department | Sail Network Co., Ltd. | ||
<br> | ||
Office: +86(0)2154223056*8004 | ||
<br> | ||
E-mail: [email protected] | ||
<br> | ||
E-Shop: www.sailnetwork.com | ||
<br> | ||
No.3-318, Lane7058, Zhongchun Rd. Shanghai, China | ||
</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from email import encoders | ||
from email.header import Header | ||
from email.mime.text import MIMEText | ||
from email.utils import parseaddr,formataddr | ||
import smtplib | ||
import time | ||
|
||
def _format_addr(s): | ||
name, addr = parseaddr(s) | ||
return formataddr((Header(name, 'utf-8').encode(), addr)) | ||
|
||
def sendEmail(fromemail,passwd,toemail,subject,text): | ||
msg = MIMEText(text, 'html', 'utf-8') | ||
msg['Subject']=Header(subject, 'utf-8').encode() | ||
msg['From'] = _format_addr(fromemail) | ||
msg['To'] = _format_addr(toemail) | ||
server=smtplib.SMTP('smtp-mail.outlook.com',587) | ||
server.starttls() | ||
server.login(fromemail,passwd) | ||
server.sendmail(fromemail, [toemail], msg.as_string()) | ||
server.quit() | ||
|
||
def load_emails(): | ||
f=open('./20160921.txt','r',encoding='utf-8').read() | ||
emails=[] | ||
for item in f.split('---'*8): | ||
try: | ||
lines=item.split('***'*4) | ||
subject=lines[0].replace('\r\n','') | ||
email=lines[1].replace('\r\n','').replace(' ','') | ||
text=lines[2] | ||
emails.append([email,subject,text]) | ||
except: | ||
continue | ||
return emails | ||
|
||
def main(): | ||
fromemail='' | ||
passwd='' | ||
emails=load_emails() | ||
for i in range(13,20): | ||
email=emails[i] | ||
sendEmail(fromemail,passwd,email[0],email[1],email[2]) | ||
time.sleep(2) | ||
print(email[1]) | ||
main() |