How to use parse_content method in pyresttest

Best Python code snippet using pyresttest_python

piece_test.py

Source:piece_test.py Github

copy

Full Screen

...7 def tearDown(self):8 pass9 def testNoAuthor(self):10 # 普通句子11 self.assertEqual(piece.parse_content(u"每个人的心里,有多么长的一个清单,这些清单里写着多少美好的事,可是,它们总是被推迟,被搁置,在时间的阁楼上腐烂。为什么勇气的问题总是被误以为是时间的问题,而那些沉重的、抑郁的、不得已的,总是被叫做生活本身。"),{12 "content":u"每个人的心里,有多么长的一个清单,这些清单里写着多少美好的事,可是,它们总是被推迟,被搁置,在时间的阁楼上腐烂。为什么勇气的问题总是被误以为是时间的问题,而那些沉重的、抑郁的、不得已的,总是被叫做生活本身。",13 "author":None,14 "work":None15 })16 def testPureEnglishWithOneWord(self):17 self.assertEqual(piece.parse_content(u"Mac-talk."),{18 "content":u"Mac-talk.",19 "author":None,20 "work":None21 })22 def testTooManySpliter(self):23 # 过多链接符忽略24 self.assertEqual(piece.parse_content("https://stacksocial.com/sales/the-mac-freebie-bundle-2-0"),{25 "content":"https://stacksocial.com/sales/the-mac-freebie-bundle-2-0",26 "author":None,27 "work":None28 })29 def testByIssue(self):30 self.assertEqual(piece.parse_content(u"It's better to fail than to pass by pure luck."),{31 "content":u"It's better to fail than to pass by pure luck.",32 "author":None,33 "work":None34 })35 def testAuthorSentance(self):36 self.assertEqual(piece.parse_content(u"我会唱歌我知道\n对于评审给我这样的肯定\n我也给予肯定\n----王菲,金曲獎十五屆最佳女演唱人得獎感言"),{37 "content":u"我会唱歌我知道\n对于评审给我这样的肯定\n我也给予肯定\n----王菲,金曲獎十五屆最佳女演唱人得獎感言",38 "author":None,39 "work":None40 })41 def testParseContent(self):42 """ testParseContent """43 self.assertEqual(piece.parse_content(u"愚蠢的人饱受其愚蠢所带来的疲累之苦。 by 叔本华"),{44 "content":u"愚蠢的人饱受其愚蠢所带来的疲累之苦。",45 "author":u"叔本华",46 "work":None47 })48 # 带言说者49 self.assertEqual(piece.parse_content(u"我们终将浑然一体,就像水溶于水。 \n——柴静"),{50 "content":u"我们终将浑然一体,就像水溶于水。",51 "author":u'柴静',52 "work":None53 })54 # 不规范破折 ------55 self.assertEqual(piece.parse_content(u"黄金真是一个奇妙的东西!谁拥有了它,谁就成为他想要的一切东西的主人,有了黄金,甚至可以使灵魂升入天堂。-------哥伦布"),{56 "content":u"黄金真是一个奇妙的东西!谁拥有了它,谁就成为他想要的一切东西的主人,有了黄金,甚至可以使灵魂升入天堂。",57 "author":u"哥伦布",58 "work":None59 })60 # 人名61 self.assertEqual(piece.parse_content(u"当下最流行三大病症:拖延症、强迫症、选择困难症,直白点说就是懒、贱、穷。----@王黎wario"),{62 "content":u"当下最流行三大病症:拖延症、强迫症、选择困难症,直白点说就是懒、贱、穷。",63 "author":u"@王黎wario",64 "work":None65 })66 # 书名67 self.assertEqual(piece.parse_content(u"我一直坚持的一个信念是,改变不了大环境,就改变小环境,做自己力所能及的事情。你不能决定太阳几点升起,但可以决定自己几点起床。——《自由在高处》"),{68 "content":u"我一直坚持的一个信念是,改变不了大环境,就改变小环境,做自己力所能及的事情。你不能决定太阳几点升起,但可以决定自己几点起床。",69 "author":None,70 "work":u"自由在高处"71 })72 # 人名及书名73 self.assertEqual(piece.parse_content(u"有时候,你很想念一个人,但你不会打电话给他。打电话给他,不知道说甚么好,还是不打比较好。想念一个人,不一定要听到他的声音。听到了他的声音也许就是另一回事。 想像中的一切往往比现实稍微美好一点。想念中的那个人也比现实稍微温暖一点。—— 约翰·肖尔斯《许愿树》"),{74 "content":u"有时候,你很想念一个人,但你不会打电话给他。打电话给他,不知道说甚么好,还是不打比较好。想念一个人,不一定要听到他的声音。听到了他的声音也许就是另一回事。 想像中的一切往往比现实稍微美好一点。想念中的那个人也比现实稍微温暖一点。",75 "author":u"约翰·肖尔斯",76 "work":u"许愿树"77 })78 self.assertEqual(piece.parse_content(u"永远不要忘记,直至上帝向人揭示出未来之日,人类全部智慧就包含在两个词中:等待和希望。 —《基督山伯爵》"),{79 "content":u"永远不要忘记,直至上帝向人揭示出未来之日,人类全部智慧就包含在两个词中:等待和希望。",80 "author": None,81 "work": u"基督山伯爵"82 })83 # 英文人名书名84 self.assertEqual(piece.parse_content(u"To choose doubt as a philosophy of life is akin to choosing immobility as a means of transportation. —— Yann Martel 《Life of Pi》"),{85 "content":u"To choose doubt as a philosophy of life is akin to choosing immobility as a means of transportation.",86 "author":u"Yann Martel",87 "work":u"Life of Pi"88 })89 # 英文人名90 self.assertEqual(piece.parse_content(u"qweqweq qwe q we qw eqw ew —— qweqwe"),{91 "content":u"qweqweq qwe q we qw eqw ew",92 "author":u"qweqwe",93 "work":None94 })95 # 过长中文认为非人名96 self.assertEqual(piece.parse_content(u"曰:我和我的小伙伴们都惊呆了?\n\n  \n\n  问:为什么惊呆了?\n\n  --这个该怎么回答"),{97 "content":u"曰:我和我的小伙伴们都惊呆了?\n\n  \n\n  问:为什么惊呆了?\n\n  --这个该怎么回答",98 "author":None,99 "work":None...

Full Screen

Full Screen

scrapy_oxford.py

Source:scrapy_oxford.py Github

copy

Full Screen

...12 elements_set = set(elements)13 seed_list = list(elements_set)14 seed_list.remove('')15 return seed_list16def parse_content(response, str_xpath):17 return ' '.join(response.xpath(str_xpath).extract())18class ScrapyOxfordSpider(scrapy.Spider):19 words = ConvertCSVfileToList()20 for (wrong, correct) in match_words:21 words[words.index(wrong)] = correct22 name = 'scrapy_oxford'23 allowed_domains = ['www.lexico.com/en/definition']24 start_urls = ['https://www.lexico.com/en/definition/' + word for word in words]25 def parse(self, response):26 word = response.request.url.split("/")[-1]27 item = []28 item.append(response.xpath('//span[contains(@class,"hw")]/text()').extract()[0] + "\n")29 for section in response.xpath('//*[@id="content"]/div[1]/div[2]/div/div/div/div/section'):30 for trg in section.xpath('./ul/li'):31 item.append(parse_content(trg,'./div/p/span[contains(@class,"ind")]/text()')+"\n")32 item.append(parse_content(trg,'./div/div[contains(@class,"exg")]/div/em/span/text()').replace("‘","").replace("’","") + "\n")33 for list in trg.xpath('./div/div[contains(@class,"examples")]/div[contains(@class,"exg")]/ul/li'):34 item.append(parse_content(list,'./em/text()').replace("‘","").replace("’","") + "\n")35 print(list.xpath('./em/text()').extract())36 #ol subSenses37 for subSenses in trg.xpath('./div/ol/li'):38 item.append(parse_content(subSenses,'./span[contains(@class,"ind")]/text()') + "\n")39 sub_discription = parse_content(subSenses,'./div[2]/div/em/span[contains(@class," one-click-content")]/text()')40 item.append(sub_discription.replace("‘","").replace("’","").lstrip()+"\n")41 for subSenses_example_sentence in subSenses.xpath('./div[3]/div[2]/ul/li'):42 item.append(parse_content(subSenses_example_sentence,'./em/text()').replace("‘","").replace("’","") + '\n')43 with open('./data/' + word +'.txt','w',encoding='UTF-8') as f:44 for element in item:45 f.write(str(element))...

Full Screen

Full Screen

domain.py

Source:domain.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import json3import logging4from pyquery import PyQuery5from backend.template import Template6from backend.util import send_request7logger = logging.getLogger(__name__)8class Domain(object):9 def __init__(self, name, parse_content=False, only_active=True, only_unprocessed=True):10 self.name = name11 self.url = "https://instantview.telegram.org/contest/{}/".format(name)12 self.templates = []13 self.parse_content = parse_content14 self.only_active = only_active15 self.only_unprocessed = only_unprocessed16 if parse_content:17 self.parse_templates()18 def add_template(self, creator=None, url=None, template=None):19 if template is None:20 logger.info("New template: {} - {}".format(creator, url))21 self.templates.append(Template(creator=creator, url=url, parse_content=self.parse_content, domain=self.name, only_unprocessed=self.only_unprocessed))22 else:23 logger.info("New template: {} - {}".format(template.creator, template.url))24 self.templates.append(template)25 def parse_templates(self):26 if len(self.templates) > 0:27 logger.error("There are already templates in here!")28 return29 domain_site = send_request(self.url)30 pq = PyQuery(domain_site)31 # Only get active templates32 if self.only_active:33 site_templates = pq(".list-group-contest").eq(0)34 else:35 # Otherwise parse rejected templates as well36 site_templates = pq(".list-group-contest")37 for template in site_templates.items(".list-group-contest-item"):38 creator = template(".contest-item-author > a").text()39 template_url = template(".contest-item-num > a").attr("href")40 self.add_template(creator, "https://instantview.telegram.org{}".format(template_url))41 def to_dict(self):42 return dict(name=self.name, url=self.url, templates=self.templates)43 @staticmethod44 def from_dict(domain_dict):45 name = domain_dict.get("name")46 url = domain_dict.get("url")47 domain = Domain(name, parse_content=False)48 templates = domain_dict.get("templates")49 for template in templates:50 template_o = Template.from_dict(template)51 domain.add_template(template=template_o)52 return domain53 def to_json(self):54 return json.dumps(self.to_dict())55 def __dict__(self):...

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