Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import re
- import threading
- fp = open("list_mobile_number.txt", "a", encoding="utf-8")
- def check_mobile_number(threadName, page):
- r = requests.get("https://www.berded.in.th/all_berded.php?id=phone&s_page=" + str(page))
- soup = BeautifulSoup(r.content, "html.parser")
- for tr in soup.find_all("tr"):
- tel = ''
- price = ''
- operator = ''
- for p in tr.find_all("span", class_="phone-mini"):
- tel = p.text
- tel = tel.replace('-', '')
- tel = tel.replace(' ', '')
- if tel == '':
- continue
- for p in tr.find_all("span", class_="price-mini"):
- price = p.text
- price = price.replace(' ฿', '')
- for p in tr.find_all("img", class_="operator"):
- operator = p['src']
- operator = operator.replace('images/logo_', '')
- operator = operator.replace('.jpg', '')
- r = requests.get('https://kainumber.com/reading/index.php?phonenumber=' + tel)
- soup2 = BeautifulSoup(r.content, "html.parser")
- l = soup2.find_all("div", class_="number_detail_right")
- weight = l[0].text.strip()
- classified = l[3].text.strip()
- l = soup2.find_all("div", class_="ndl_head")
- element = l[4].text.strip()
- msg = tel + ' ' + price + ' ' + operator + ' ' + weight
- print( msg )
- fp.write( msg + ' ' + classified + ' ' + element + '\n' )
- class myThread (threading.Thread):
- def __init__(self, threadID, page):
- threading.Thread.__init__(self)
- self.threadID = threadID
- self.page = page
- def run(self):
- print ("Starting " + str(self.threadID))
- print ("Page " + str(self.page))
- check_mobile_number(self.threadID, self.page)
- print ("Exiting " + str(self.threadID))
- for page in range(0, 100):
- try:
- thread0 = myThread(0, page*10 + 0 )
- thread1 = myThread(1, page*10 + 1 )
- thread2 = myThread(2, page*10 + 2 )
- thread3 = myThread(3, page*10 + 3 )
- thread4 = myThread(4, page*10 + 4 )
- thread5 = myThread(5, page*10 + 5 )
- thread6 = myThread(6, page*10 + 6 )
- thread7 = myThread(7, page*10 + 7 )
- thread8 = myThread(8, page*10 + 8 )
- thread9 = myThread(9, page*10 + 9 )
- thread0.start()
- thread1.start()
- thread2.start()
- thread3.start()
- thread4.start()
- thread5.start()
- thread6.start()
- thread7.start()
- thread8.start()
- thread9.start()
- thread0.join()
- thread1.join()
- thread2.join()
- thread3.join()
- thread4.join()
- thread5.join()
- thread6.join()
- thread7.join()
- thread8.join()
- thread9.join()
- thread10.join()
- except:
- print( "Error: unable to start thread" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement