Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.96 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import re
  4. import threading
  5.  
  6.  
  7. fp = open("list_mobile_number.txt", "a", encoding="utf-8")
  8.  
  9. def check_mobile_number(threadName, page):
  10.     r = requests.get("https://www.berded.in.th/all_berded.php?id=phone&s_page=" + str(page))
  11.     soup = BeautifulSoup(r.content, "html.parser")
  12.  
  13.  
  14.     for tr in soup.find_all("tr"):
  15.         tel = ''
  16.         price = ''
  17.         operator = ''
  18.  
  19.         for p in tr.find_all("span", class_="phone-mini"):
  20.             tel = p.text
  21.             tel = tel.replace('-', '')
  22.             tel = tel.replace(' ', '')
  23.  
  24.         if tel == '':
  25.             continue
  26.  
  27.         for p in tr.find_all("span", class_="price-mini"):
  28.             price = p.text
  29.             price = price.replace(' ฿', '')
  30.        
  31.         for p in tr.find_all("img", class_="operator"):
  32.             operator = p['src']
  33.             operator = operator.replace('images/logo_', '')
  34.             operator = operator.replace('.jpg', '')
  35.        
  36.         r = requests.get('https://kainumber.com/reading/index.php?phonenumber=' + tel)
  37.        
  38.         soup2 = BeautifulSoup(r.content, "html.parser")
  39.         l = soup2.find_all("div", class_="number_detail_right")
  40.         weight = l[0].text.strip()
  41.         classified = l[3].text.strip()
  42.  
  43.         l = soup2.find_all("div", class_="ndl_head")
  44.         element = l[4].text.strip()
  45.  
  46.  
  47.  
  48.         msg = tel + '   ' + price + '   ' + operator + '    ' + weight
  49.         print( msg )
  50.         fp.write( msg + '  ' + classified + '   ' + element  + '\n' )
  51.  
  52. class myThread (threading.Thread):
  53.    def __init__(self, threadID, page):
  54.       threading.Thread.__init__(self)
  55.       self.threadID = threadID
  56.       self.page = page
  57.    def run(self):
  58.       print ("Starting " + str(self.threadID))
  59.       print ("Page " + str(self.page))
  60.       check_mobile_number(self.threadID, self.page)
  61.       print ("Exiting " + str(self.threadID))
  62.  
  63. for page in range(0, 100):
  64.     try:
  65.         thread0 = myThread(0, page*10 + 0 )
  66.         thread1 = myThread(1, page*10 + 1 )
  67.         thread2 = myThread(2, page*10 + 2 )
  68.         thread3 = myThread(3, page*10 + 3 )
  69.         thread4 = myThread(4, page*10 + 4 )
  70.         thread5 = myThread(5, page*10 + 5 )
  71.         thread6 = myThread(6, page*10 + 6 )
  72.         thread7 = myThread(7, page*10 + 7 )
  73.         thread8 = myThread(8, page*10 + 8 )
  74.         thread9 = myThread(9, page*10 + 9 )
  75.  
  76.         thread0.start()
  77.         thread1.start()
  78.         thread2.start()
  79.         thread3.start()
  80.         thread4.start()
  81.         thread5.start()
  82.         thread6.start()
  83.         thread7.start()
  84.         thread8.start()
  85.         thread9.start()
  86.  
  87.         thread0.join()
  88.         thread1.join()
  89.         thread2.join()
  90.         thread3.join()
  91.         thread4.join()
  92.         thread5.join()
  93.         thread6.join()
  94.         thread7.join()
  95.         thread8.join()
  96.         thread9.join()
  97.         thread10.join()
  98.        
  99.     except:
  100.         print( "Error: unable to start thread" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement