Best Python code snippet using pyresttest_python
reportGenerator.py
Source:reportGenerator.py
...139 list_rt = sorted(list(keyword_dict.keys()), key=lambda x: keyword_dict[x], reverse=True)140 return list_rt[0], keyword_dict[list_rt[0]]141142143def get_set_url():144 set_url = set()145 with open('Token_File.txt', 'r') as tk_f:146 while True:147 #-----http://www.cs.uci.edu/148 ln = tk_f.readline()149 if ln[:5] == '-----':150 #url line151 set_url.add(ln)152 if ln == '':153 break154 return set_url155156157def get_sub(urls):158 # get subdomains159 sub = defaultdict(int)160 for i in urls:161 parsed = urlparse(i)162 domain = parsed.netloc163 subdomain = parsed.hostname.split('.')[0]164 sub_url = parsed.scheme + "://" + subdomain + ".ics.uci.edu"165 if re.match(r"(.*\.)?ics\.uci\.edu", domain):166 if sub_url in sub:167 sub[sub_url] += 1168 else:169 sub[sub_url] = 1170 return sub171172def write_file(sub):173 # Writes file for answering number 4 based on the subdomains that we gathered.174 alpha = sorted(sub.items())175 with open("Report.txt", "a") as a:176 a.write("Question 4: How many subdomains did you find in the ics.uci.edu domain?\n")177 for l in alpha:178 text = "Subdomain: "+str(l[0])+", "+str(l[1])+" times found\n"179 a.write(text)180181182183184185186187if __name__ == '__main__':188 189 urls = get_set_url()190 with open("Report.txt", 'w') as rpt:191 rpt.write("Question 1: How many unique pages did we find?\n")192 rpt.write("We found total: "+str(len(urls))+" pages\n\n")193 194 195 list1 = top_50(urls)196 urls = get_set_url()197 with open('Report.txt', 'a') as rpt:198 rpt.write("Question 2: What is the longest page in terms of number of words?\n")199 rpt.write(str(longest_page(urls))+'\n\n')200 201 202 with open('Report.txt', 'a') as rpt:203 rpt.write("Question 3: What are the 50 common words for the pages we crawled under these domains?\n")204 for i in range(50):205 rpt.write(str(list1[i])+'\n')206 rpt.write('\n')207208 write_file(get_sub(urls))
...
Focus_Spider.py
Source:Focus_Spider.py
1#!/usr/bin/env python2# -*- coding: UTF-8 -*-3#-------------------------------------------------------------------------4# ç¨åºï¼Focus_Spider.py5# çæ¬ï¼0.16# ä½è
ï¼ly7# æ¥æï¼ç¼åæ¥æ2016/11/108# è¯è¨ï¼Python 2.7.x9# æä½ï¼python Focus_Spider.py10# åè½ï¼æµè¯èç¦ç¬è«,èªå¨æåurlteamç½ç«çå
¨é¨url.å¯ä»¥éè¿ä¿®æ¹æ£åæ¥è°æ´å¹é
å°url11# éè¿.ä¿®æ¹mainä¸ç导å
¥urlæ¥è®¾ç½®å
¥å£ç½ç«.æç´¢æ¹å¼æ¯éæº,éçæ°å¼çå¢å å¹é
深度12#13#-------------------------------------------------------------------------14import re, requests, sys, random15#--------------------------------------------------16#ä¸æç¼ç 设置17reload(sys)18sys.setdefaultencoding('utf-8')19Type = sys.getfilesystemencoding()20set_url = set() # é²æ¢éå¤21def requests_url(url):22 try:23 page_html = requests.get(url).text.encode('utf-8')24 #print page_html25 #url_list = re.findall('http://.*\'',page_html)26 url_list = re.findall('''https?://.{4}urlteam[^"<>()\s']+''',page_html)27 for i in url_list:28 if( i.find('.jpg')==-1 and i.find('.png')==-1 and i.find('/js/')==-1 and i.find('.css?')==-1 and i.find('.js')==-1 ):29 #print i30 set_url.update([i])31 return set_url32 #print url_list33 except Exception,e:34 print Exception,e35if __name__=='__main__':36 #å
¥å£37 url = 'https://www.urlteam.org'38 requests_url(url)39 #print set_url40 #print len(set_url)41 num = 400 #设置éæºæ¬¡æ°.éæ设置ç¨äºæµè¯42 while(num):43 l = len(set_url)44 n = random.randint(0,l)45 temp_flag = 046 for temp_url in set_url:47 temp_flag += 148 if temp_flag == n:49 break50 url = temp_url51 print num,temp_url,url52 try:53 requests_url(url)54 except Exception,e:55 print Exception,e56 print len(set_url)57 num -= 158#--------------------------------------------------59#åå
¥æ件.60 print set_url61 print len(set_url)62 f = open('set.txt','w')63 f.write(str(set_url))64 f.write(str(len(set_url)))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!