ddt 使用操作


import requests import ddt import unittest url = 'https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false' def getHeader(): headers = { 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36', 'Referer':'https://www.lagou.com/jobs/list_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E5%B7%A5%E7%A8%8B%E5%B8%88?labelWords=&fromSearch=true&suginput=', 'Cookie':'JSESSIONID=ABAAABAAAEEAAII2746DF2F863570099E4EB907A4631D1D; WEBTJ-ID=20200304094813-170a33aa110503-07f6b803ca1cb1-376b4502-2073600-170a33aa111565; _ga=GA1.2.887675131.1583286494; Hm_lvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1583286494; user_trace_token=20200304094813-a04df307-9251-4f2d-9e6d-9a0aab6e86f4; LGUID=20200304094813-a6998d1c-ff0a-43a6-bd68-6e909267a136; _gid=GA1.2.1269276585.1583286494; sajssdk_2015_cross_new_user=1; index_location_city=%E5%85%A8%E5%9B%BD; TG-TRACK-CODE=index_search; ab_test_random_num=0; LG_HAS_LOGIN=1; hasDeliver=0; privacyPolicyPopup=false; showExpriedIndex=1; showExpriedCompanyHome=1; showExpriedMyPublish=1; X_MIDDLE_TOKEN=a3ad85cd6beac66654efd81f2425e3b9; login=false; unick=""; _putrc=""; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22170a33ab7f2369-071c191bfe761f-376b4502-2073600-170a33ab7f377d%22%2C%22%24device_id%22%3A%22170a33ab7f2369-071c191bfe761f-376b4502-2073600-170a33ab7f377d%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%7D%7D; LGSID=20200304115357-9cba0b8c-5b87-4c7d-8aea-cf70acde7adb; PRE_UTM=; PRE_HOST=; PRE_SITE=https%3A%2F%2Fwww.lagou.com; PRE_LAND=https%3A%2F%2Fwww.lagou.com%2Fjobs%2Flist%5F%25E8%2587%25AA%25E5%258A%25A8%25E5%258C%2596%25E6%25B5%258B%25E8%25AF%2595%25E5%25B7%25A5%25E7%25A8%258B%25E5%25B8%2588%2Fp-city%5F0%3F%26cl%3Dfalse%26fromSearch%3Dtrue%26labelWords%3D%26suginput%3D; _gat=1; SEARCH_ID=d5589236cfa644d5ab8e6eff4c1081af; X_HTTP_TOKEN=3f2e2c590e7be56b6154923851dc9c15721eed0302; Hm_lpvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1583294517; LGRID=20200304120156-c1ae9105-f5e0-4255-b8fe-511c0a88332a' } return headers def getData(page): data = { 'first':'False', 'pn':page, 'kd':'自动化测试工程师', 'sid':'0f12dfacd9d04d8d9a010ad9fa819a84' } return data @ddt.ddt class LaGou(unittest.TestCase): @ddt.data((1,),(2,),(3,),(4,),(5,),(6,)) @ddt.unpack def test_laGou(self,page): r = requests.post( url=url, headers=getHeader(), data=getData(page) ) # print(r.json()['success']) self.assertEqual(r.json()['success'],True) print(r.json()['content']['positionResult']['result'][0]['city']) if __name__ == '__main__': unittest.main(verbosity=2)

  

原文地址:https://www.cnblogs.com/siyu0123/p/12843906.html