How to use set_url method in pyresttest

Best Python code snippet using pyresttest_python

reportGenerator.py

Source:reportGenerator.py Github

copy

Full Screen

...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)) ...

Full Screen

Full Screen

Focus_Spider.py

Source:Focus_Spider.py Github

copy

Full Screen

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)))...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyresttest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful