url20 = 'https://clientarea.ramnode.com/cart.php?gid=42' url21 = 'https://clientarea.ramnode.com/cart.php?gid=43' url22 = 'https://clientarea.ramnode.com/cart.php?gid=44' url23 = 'https://clientarea.ramnode.com/cart.php?gid=45' url24 = 'https://clientarea.ramnode.com/cart.php?gid=46' url25 = 'https://clientarea.ramnode.com/cart.php?gid=47' url26 = 'https://clientarea.ramnode.com/cart.php?gid=49' url27 = 'https://clientarea.ramnode.com/cart.php?gid=50' url28 = 'https://clientarea.ramnode.com/cart.php?gid=51' url29 = 'https://clientarea.ramnode.com/cart.php?gid=52' url30 = 'https://clientarea.ramnode.com/cart.php?gid=53' try: all_info = {} notice = '' for i in range(1,31): response = requests_pkg.get(eval('url'+str(i))) if response is None: email_sender.send_email('ramnode','没抓到网页') else: response_body = response.content content_type = chardet.detect(response_body) if content_type['encoding'] != "UTF-8": response_body = response_body.decode(content_type['encoding'], 'ignore') response_body = response_body.encode("utf-8", 'ignore') # 实时入库 html_body = response.text.encode("GBK", 'ignore') #print html_body searchObj = re.findall(r'<div class="price-container container-with-progress-bar text-center">(.*?)</div>',response_body, re.S|re.I) titleObj = re.search( r'<h2 id="headline">(.*?)</h2>', response_body, re.S|re.I)
'1801armada01': 'ARM-2T(FRA)', '1801armada02': 'ARM-4T(FRA)', '1801armada03': 'ARM-6T(FRA)' } try: all_info = { 'ARM-2T(CAN)': '0', 'ARM-4T(CAN)': '0', 'ARM-6T(CAN)': '0', 'ARM-2T(FRA)': '0', 'ARM-4T(FRA)': '0', 'ARM-6T(FRA)': '0' } notice = '' response = requests_pkg.get(url) if response is None: email_sender.send_email('soyoustart', '没抓到网页') else: response_body = response.content content_type = chardet.detect(response_body) if content_type['encoding'] != "UTF-8": response_body = response_body.decode(content_type['encoding'], 'ignore') response_body = response_body.encode("utf-8", 'ignore') # 实时入库 all_vps = json.loads(response_body) ks_vps_names = types.keys() for item in all_vps: if item['hardware'] in ks_vps_names:
import MySQLdb import db_conf from db_helper import db_helper_class import requests_pkg from email_server.email_sender_calss import email_sender_calss db_oper = db_helper_class() email_sender = email_sender_calss() #洛杉矶-亚洲优化KVM url1 = 'https://hostodo.com/portal/cart.php?gid=36' #洛杉矶-KVM url2 = 'https://hostodo.com/portal/cart.php?gid=34' #迈阿密-KVM url3 = 'https://hostodo.com/portal/cart.php?gid=35' try: response1 = requests_pkg.get(url1) response2 = requests_pkg.get(url2) response3 = requests_pkg.get(url3) if response1 is None or response2 is None or response3 is None: email_sender.send_email('hostodo', '没抓到网页') else: #print response.text.encode("GBK", 'ignore') response_body = response1.content + response2.content + response3.content content_type = chardet.detect(response_body) if content_type['encoding'] != "UTF-8": response_body = response_body.decode(content_type['encoding'], 'ignore') response_body = response_body.encode("utf-8", 'ignore') # 实时入库