本文整理汇总了Python中pyquery.pq函数的典型用法代码示例。如果您正苦于以下问题:Python pq函数的具体用法?Python pq怎么用?Python pq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pq函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__render
def test__render(self):
w = MultiEmailWidget()
output = w.render('test', ['[email protected]', '[email protected]'])
self.assertEqual(1, len(pq('textarea', output)))
self.assertEqual(
pq('textarea', output).text(),
'[email protected],[email protected]')
示例2: test_delete
def test_delete(self):
"""Can delete badge"""
user = self._get_user()
badge = Badge(creator=user, title="Test III",
description="Another test")
badge.save()
slug = badge.slug
badge.award_to(user)
self.client.login(username="tester", password="trustno1")
r = self.client.get(reverse('badger.views.detail',
args=(badge.slug,)), follow=True)
doc = pq(r.content)
eq_('badge_detail', doc.find('body').attr('id'))
delete_url = doc.find('a.delete_badge').attr('href')
ok_(delete_url is not None)
r = self.client.get(delete_url)
doc = pq(r.content)
eq_('badge_delete', doc.find('body').attr('id'))
eq_("1", doc.find('.awards_count').text())
r = self.client.post(delete_url, {}, follow=True)
doc = pq(r.content)
try:
badge = Badge.objects.get(slug=slug)
ok_(False)
except Badge.DoesNotExist:
ok_(True)
示例3: scrape_press_releases
def scrape_press_releases():
releases_page = pq(scraperwiki.scrape(BASE_URL + 'news-releases'))
for row in releases_page.find('.recordListTitle'):
sleep(1)
title = ''
date = None
content = ''
attachments = []
links = pq(row).find('a')
page = pq(scraperwiki.scrape(links.eq(0).attr('href')))
title = _extract_title_from(page)
content = _readable(page.find('.content').html())
date = _extract_date_from(page)
for attachment in page.find('.file_link a'):
att = pq(attachment)
attachments.append({att.text(): att.attr('html')})
args = [title, date, content]
kwargs = {}
if len(attachments):
kwargs.update(attachments=attachments)
gasp.add_press_release(*args, **kwargs)
示例4: test_bug869301_revisions_feed_locale
def test_bug869301_revisions_feed_locale(self):
"""Links to documents in revisions feed with ?all_locales should
reflect proper document locale, regardless of requestor's locale"""
d = document(title='HTML9', locale="fr")
d.save()
now = datetime.datetime.now()
for i in xrange(1, 6):
created = now + datetime.timedelta(seconds=5 * i)
revision(save=True,
document=d,
title='HTML9',
comment='Revision %s' % i,
content="Some Content %s" % i,
is_approved=True,
created=created)
resp = self.client.get('%s?all_locales' %
reverse('wiki.feeds.recent_revisions',
args=(),
kwargs={'format': 'rss'},
locale='en-US'))
self.assertEqual(200, resp.status_code)
feed = pq(resp.content)
self.assertEqual(5, len(feed.find('item')))
for i, item in enumerate(feed.find('item')):
href = pq(item).find('link').text()
self.assertTrue('/fr/' in href)
示例5: run
def run(self):
opener = build_opener(HTTPCookieProcessor())
d = pq(opener.open(self.url).read())
rates = d(".count")
self.descrip = pq(rates[0]).html()
self.service = pq(rates[1]).html()
self.speed = pq(rates[2]).html()
示例6: test_top_contributors
def test_top_contributors(self):
# There should be no top contributors since there are no solutions.
cache_top_contributors()
response = get(self.client, 'questions.questions')
doc = pq(response.content)
eq_(0, len(doc('#top-contributors ol li')))
# Solve a question and verify we now have a top conributor.
answer = Answer.objects.all()[0]
answer.created = datetime.now()
answer.save()
answer.question.solution = answer
answer.question.save()
cache_top_contributors()
response = get(self.client, 'questions.questions')
doc = pq(response.content)
lis = doc('#top-contributors ol li')
eq_(1, len(lis))
eq_('pcraciunoiu', lis[0].text)
# Make answer 8 days old. There should no be top contributors.
answer.created = datetime.now() - timedelta(days=8)
answer.save()
cache_top_contributors()
response = get(self.client, 'questions.questions')
doc = pq(response.content)
eq_(0, len(doc('#top-contributors ol li')))
示例7: ods2csv
def ods2csv(content,admins=''):
file_like_object = StringIO(content)
xml = zipfile.ZipFile(file_like_object).read('content.xml')
def rep_repl(match):
return '<table:table-cell>%s' %match.group(2) * int(match.group(1))
def repl_empt(match):
n = int(match.group(1))
pat = '<table:table-cell/>'
return pat*n if (n<100) else pat
p_repl = re.compile(r'<table:table-cell [^>]*?repeated="(\d+)[^/>]*>(.+?table-cell>)')
p_empt = re.compile(r'<table:table-cell [^>]*?repeated="(\d+)[^>]*>')
xml = re.sub(p_repl, rep_repl, xml)
xml = re.sub(p_empt, repl_empt, xml)
d = pq(xml, parser='xml')
ns={'table': 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'}
selr = CSSSelector('table|table-row', namespaces=ns)
selc = CSSSelector('table|table-cell', namespaces=ns)
rowxs = pq(selr(d[0]))
data = []
for ir,rowx in enumerate(rowxs):
cells = pq(selc(rowx))
if cells.text():
data.append([cells.eq(ic).text().encode('utf-8') for ic in range(len(cells))])
if data:
return data
else:
logger_script=logging.getLogger("Script Error")
logger_script.warning("Google retuned empty file for table <b>%s</b>" % IP_table_name)
sending_log("DHCP_ERROR: script got an error","<b>Google returned empty file</b>, script ended without any changes made!",error_log_file_name=error_log_file_name,admins=admins)
sys.exit(exit_code_dict['google_returned_empty_file'])
示例8: test_support_link
def test_support_link(self):
# Test no link if no support url or contribution.
self.enable_waffle()
r = self.client.get(self.add)
eq_(pq(r.content)('.support-link').length, 0)
# Test support email if no support url.
self.webapp.support_email = {'en-US': '[email protected]'}
self.webapp.save()
r = self.client.get(self.add)
doc = pq(r.content)('.support-link')
eq_(doc.length, 1)
# Test link to support url if support url.
self.webapp.support_url = {'en-US': 'test'}
self.webapp.save()
r = self.client.get(self.add)
doc = pq(r.content)('.support-link a')
eq_(doc.length, 1)
eq_(doc.attr('href'), 'test')
# Test link to support flow if contribution.
c = Contribution.objects.create(addon=self.webapp, user=self.user,
type=amo.CONTRIB_PURCHASE)
r = self.client.get(self.add)
doc = pq(r.content)('.support-link a')
eq_(doc.length, 1)
eq_(doc.attr('href'), reverse('support', args=[c.id]))
示例9: test_post_bad_site
def test_post_bad_site(self):
self.client.login(username='featuretest', password='pword')
url = '/datasheet/bulk_import/'
with open(self.fpath_bad_site) as f:
response = self.client.post(url, {
'datasheet_id': self.ds.pk,
'organization': 'Coast Savers',
'project_id': 1,
'csvfile': f
}
)
d = pq(response.content)
el = d("ul.errorlist li")
self.assertEqual(response.status_code, 400, response.content)
self.assertEqual(len(el), 1)
self.assertTrue("TestSite3" in el[0].text_content(), el[0].text_content())
self.assertTrue("is not in the database" in el[0].text_content(), el[0].text_content())
# Now add the site
ca = State.objects.get(name="California")
testsite3 = Site(sitename="TestSite3", state=ca, county="Santa Cruz")
testsite3.save()
with open(self.fpath_bad_site) as f:
response = self.client.post(url, {
'datasheet_id': self.ds.pk,
'organization': 'Coast Savers',
'project_id': 1,
'csvfile': f
}
)
d = pq(response.content)
el = d("ul.errorlist li")
self.assertEqual(response.status_code, 200, response.content)
self.assertEqual(len(el), 0)
示例10: test_known_authors_filter
def test_known_authors_filter(self):
# There are a total of 11 revisions
url = urlparams(reverse('dashboards.revisions', locale='en-US'),
authors=RevisionDashboardForm.ALL_AUTHORS)
response = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
eq_(response.status_code, 200)
page = pq(response.content)
revisions = page.find('.dashboard-row')
eq_(11, revisions.length)
# Only testuser01 is in the Known Authors group, and has 2 revisions
url = urlparams(reverse('dashboards.revisions', locale='en-US'),
authors=RevisionDashboardForm.KNOWN_AUTHORS)
response = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
eq_(response.status_code, 200)
page = pq(response.content)
revisions = page.find('.dashboard-row')
eq_(2, revisions.length)
# Of the 11 revisions, 9 are by users not in the Known Authors group
url = urlparams(reverse('dashboards.revisions', locale='en-US'),
authors=RevisionDashboardForm.UNKNOWN_AUTHORS)
response = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
eq_(response.status_code, 200)
page = pq(response.content)
revisions = page.find('.dashboard-row')
eq_(9, revisions.length)
示例11: test_bug_709938_interests
def test_bug_709938_interests(self):
testuser = self.user_model.objects.get(username='testuser')
self.client.login(username=testuser.username,
password=TESTUSER_PASSWORD)
url = reverse('users.user_edit', args=(testuser.username,))
response = self.client.get(url, follow=True)
doc = pq(response.content)
test_tags = [u'science,Technology,paradox,knowledge,modeling,big data,'
u'vector,meme,heuristics,harmony,mathesis universalis,'
u'symmetry,mathematics,computer graphics,field,chemistry,'
u'religion,astronomy,physics,biology,literature,'
u'spirituality,Art,Philosophy,Psychology,Business,Music,'
u'Computer Science']
form = self._get_current_form_field_values(doc)
form['user-interests'] = test_tags
response = self.client.post(url, form, follow=True)
eq_(200, response.status_code)
doc = pq(response.content)
eq_(1, doc.find('ul.errorlist li').length)
assert ('Ensure this value has at most 255 characters'
in doc.find('ul.errorlist li').text())
示例12: get_perm
def get_perm(perm):
jq = pq(
"http://www1.appstate.edu/cgi-bin/cgiwrap/jmm/newcso4.pl",
data={"last": name, "first": "{}*".format(perm), "type": "student"},
method="post",
)
over = len(jq("p:contains('too many results')"))
if not (over):
return [
{
"Name": re.findall(r"name\: .*", pq(x).text())[0]
.replace("name:", "")
.strip()
.encode("utf-8"),
"Email": pq(x)("a[href^=mailto]").text(),
}
for x in jq("#maintext table tr:gt(0) td pre")
if re.findall(r"name\: .*", pq(x).text())
]
else:
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as thread:
return list(
itertools.chain(
*list(
thread.map(
get_perm,
["{}{}".format(perm, x) for x in get_character_permutations(num_characters=1)],
)
)
)
)
示例13: parse_count_by_use
def parse_count_by_use(html, city):
#dir_name = get_result_path()
file_name1 = os.path.join(dir_name, 'shenzhen_gov_ershoufang_count_by_use_day_region.txt')
file_name2 = os.path.join(dir_name, 'shenzhen_gov_ershoufang_count_by_use_month_region.txt')
table1 = pq(html)("#ctl00_ContentPlaceHolder1_clientList1 tr")
table2 = pq(html)("#ctl00_ContentPlaceHolder1_clientList2 tr")
date1 = pq(html)('#ctl00_ContentPlaceHolder1_lblCurTime1').text()
date2 = pq(html)('#ctl00_ContentPlaceHolder1_lblCurTime2').text()
infos1 = infos2 = ''
if os.path.exists(file_name1):
fr = open(file_name1, 'r')
infos1 = fr.read().decode('utf8')
fr.close()
if os.path.exists(file_name2):
fr = open(file_name2, 'r')
infos2 = fr.read().decode('utf8')
fr.close()
#print len(table1)
#print len(table2)
info1 = get_info(table1, date1, city)
#print 'table2'
info2 = get_info(table2, date2, city)
#print 'end table2'
if date1 + ',' + city not in infos1:
fw1 = open(file_name1, 'a')
fw1.write(','.join(info1).encode('utf8') + '\n')
fw1.close()
#print 'end date1'
if date2 + ',' + city not in infos2:
fw2 = open(file_name2, 'a')
fw2.write(','.join(info2).encode('utf8') + '\n')
fw2.close()
示例14: common_answer_vote
def common_answer_vote(self):
"""Helper method for answer vote tests."""
# Check that there are no votes and vote form renders
response = get(self.client, 'questions.answers',
args=[self.question.id])
doc = pq(response.content)
eq_(1, len(doc('form.helpful input[name="helpful"]')))
# Vote
post(self.client, 'questions.answer_vote', {'helpful': 'y'},
args=[self.question.id, self.answer.id])
# Check that there is 1 vote and vote form doesn't render
response = get(self.client, 'questions.answers',
args=[self.question.id])
doc = pq(response.content)
eq_('1 out of 1 person', doc('#answer-1 div.helpful mark')[0].text)
eq_(0, len(doc('form.helpful input[name="helpful"]')))
# Voting again (same user) should not increment vote count
post(self.client, 'questions.answer_vote', {'helpful': 'y'},
args=[self.question.id, self.answer.id])
doc = pq(response.content)
eq_('1 out of 1 person', doc('#answer-1 div.helpful mark')[0].text)
示例15: get_results
def get_results(self, response, sort=True):
"""Return pks of add-ons shown on search results page."""
addons = pq(response.content)('#pjax-results div[data-addon]')
pks = [int(pq(a).attr('data-addon')) for a in addons]
if sort:
return sorted(pks)
return pks