1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sun Mar 11 16:03:44 2018 @author: beast """ from random import * file_limit=50000 #a file with (size) number of characters with open ("random.txt","w") as file : for i in range (file_limit): start=choice([48,65,97]) #make choice among three group i.e whether new character should be a digit ,uppercase or lowercase character end=0 #initialize end with 0 if start==48:end=58 # deicde end point elif start==65:end=91 else:end=123 breakrnd=randint(0,2) breakrnd2=randint(0,2) breakrnd3=randint(0,2) breakrnd4=randint(0,2) rand=randrange(start,end)#now select any character from given range file.write("{0:c}".format(rand)) # writing character obtained from ascii code ... if breakrnd*breakrnd2*breakrnd3*breakrnd4==1 : # random places inserting breaks eg a new line or etc brk=choice(["\n","\t"," "]) file.write(brk) |
import requests import urllib.request import time from bs4 import BeautifulSoup as bs import re url = ' https://en.wikipedia.org/wiki/Mobile_telephone_numbering_in_India' state_to_extract = "UE" #if set to None all state is considered telecom_to_extracted = None #if set to none all operator from particular city is extracted response = requests . get(url) print (response) soup = bs(response . text, "html.parser" ) one_a_tag = soup . findAll( 'tr' )[ 35 :] lst = [] for k in one_a_tag: s = k . findAll( 'td' ) limit = len (s) i = 0 while True : if i == limit: break no = s[i] . text i += 1 if i == limit: break operator = s[i] . text i += 1 if i == limit: break state = s[i] . text i += 1 if i == limit: break res = f "{no} {operator} {state}" if state_to_extract is None : if telecom_to_extracted is None : lst . append(no) elif telecom_to_e...
Comments
Post a Comment
share your thoughts ....