本文整理汇总了Python中pyquery.pq函数的典型用法代码示例。如果您正苦于以下问题:Python pq函数的具体用法?Python pq怎么用?Python pq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pq函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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]')
开发者ID:Vadimus,项目名称:django-multi-email-field,代码行数:7,代码来源:tests.py
示例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)
开发者ID:askvictor,项目名称:django-badger,代码行数:33,代码来源:test_views.py
示例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)
开发者ID:carriercomm,项目名称:scraperwiki-scraper-vault,代码行数:25,代码来源:gasp_python_scraper_11.py
示例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)
开发者ID:15ramky,项目名称:kuma,代码行数:27,代码来源:test_feeds.py
示例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()
开发者ID:pioneerwxf,项目名称:markpro,代码行数:7,代码来源:taobao.py
示例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')))
开发者ID:MechanisM,项目名称:kitsune,代码行数:27,代码来源:test_templates.py
示例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'])
开发者ID:Ishayahu,项目名称:MJCC-tasks,代码行数:35,代码来源:Gtable_to_files_with_template.py
示例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]))
开发者ID:mozillageckoboard,项目名称:zamboni,代码行数:28,代码来源:test_views.py
示例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)
开发者ID:Ecotrust,项目名称:wc-marine-debris,代码行数:34,代码来源:tests.py
示例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)
开发者ID:tsl143,项目名称:kuma,代码行数:33,代码来源:test_views.py
示例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())
开发者ID:digisu,项目名称:kuma,代码行数:26,代码来源:test_views.py
示例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)],
)
)
)
)
开发者ID:evanmosseri,项目名称:University-Directory-Scraping,代码行数:31,代码来源:illinois_urbana.py
示例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()
开发者ID:shineforever,项目名称:ops,代码行数:32,代码来源:shenzhen_gov_ershoufang1.py
示例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)
开发者ID:MechanisM,项目名称:kitsune,代码行数:25,代码来源:test_templates.py
示例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
开发者ID:bqbn,项目名称:addons-server,代码行数:7,代码来源:test_views.py
示例16: test_answer_creator_can_edit
def test_answer_creator_can_edit(self):
"""The creator of an answer can edit his/her answer."""
self.client.login(username='rrosario', password='testpass')
# Initially there should be no edit links
response = get(self.client, 'questions.answers',
args=[self.question.id])
doc = pq(response.content)
eq_(0, len(doc('ol.answers a.edit')))
# Add an answer and verify the edit link shows up
content = 'lorem ipsum dolor sit amet'
response = post(self.client, 'questions.reply',
{'content': content},
args=[self.question.id])
doc = pq(response.content)
eq_(1, len(doc('ol.answers a.edit')))
new_answer = self.question.answers.order_by('-created')[0]
eq_(1, len(doc('#answer-%s a.edit' % new_answer.id)))
# Make sure it can be edited
content = 'New content for answer'
response = post(self.client, 'questions.edit_answer',
{'content': content},
args=[self.question.id, new_answer.id])
eq_(200, response.status_code)
# Now lock it and make sure it can't be edited
self.question.is_locked = True
self.question.save()
response = post(self.client, 'questions.edit_answer',
{'content': content},
args=[self.question.id, new_answer.id])
eq_(403, response.status_code)
开发者ID:MechanisM,项目名称:kitsune,代码行数:34,代码来源:test_templates.py
示例17: test_perf_warning
def test_perf_warning(self):
eq_(self.addon.ts_slowness, None)
doc = pq(self.client.get(self.detail_url).content)
eq_(doc('.performance-note').length, 0)
self.addon.update(ts_slowness=100)
doc = pq(self.client.get(self.detail_url).content)
eq_(doc('.performance-note').length, 1)
开发者ID:vaidik,项目名称:zamboni,代码行数:7,代码来源:test_views.py
示例18: get_autolab_grades
def get_autolab_grades():
#Autolab has their SSL certificates misconfigured, so we won't verify them
s = authenticate('https://autolab.cs.cmu.edu/auth/users/auth/shibboleth',{"verify":False})
main = s.get('https://autolab.cs.cmu.edu').content
d = pq(main)
current_courses = d('#content > .rolodex > .course > h1 > a')
grades = {}
for course in current_courses:
page_1 = s.get('https://autolab.cs.cmu.edu%s/assessments' % d(course).attr('href')).content
gradebook = pq(pq(page_1)('.action-links > li > a')[1]).attr('href')
course_page = s.get('https://autolab.cs.cmu.edu%s' % gradebook).content
course_name = d(course).text()
cd = pq(course_page)
grades[course_name] = {}
assignments = cd('.grades tr')
for assgn in assignments:
if d(assgn).attr('class') == 'header': continue
name = cd(assgn).find("td > span > a").text()
score = cd(assgn).find("td > a").text()
total = cd(assgn).find("span.max_score").text()
if name is not None and score is not None and total is not None:
grades[course_name][name] = [float(score), float(total)]
return grades
开发者ID:wangdwes,项目名称:cmu-grades,代码行数:32,代码来源:grades.py
示例19: scrape_inspection
def scrape_inspection(inspection_url, facility):
try:
inspection = {}
inspection['facility'] = facility['_id']
if 'id' in facility:
inspection['facility_id'] = facility['id']
inspection['_id'] = inspection_url
inspection['url'] = inspection_url
inspection_resp = requests.get(inspection['url'])
doc = pq(inspection_resp.content)
info = doc.find('div#inspectionInfo tr td')
for (counter, pair) in enumerate(grouper(info, 2)):
value = pq(pair[1]).text()
if counter == 0:
date = dateutil.parser.parse(value)
inspection['date'] = date.date()
elif counter == 2:
inspection['priority'] = value
elif counter == 3:
inspection['purpose'] = value
elif counter == 4:
inspection['result'] = value
elif counter == 5:
inspection['actions'] = value
print "inspection: %s" % inspection
save_inspection(inspection)
return inspection, inspection_resp
except:
logger.exception("Could not scrape inspection %s" %
inspection.get('url', ''))
开发者ID:mwic,项目名称:python-scrapers,代码行数:32,代码来源:thd_food_inspections.py
示例20: test_map
def test_map(self):
def ids_minus_one(i, elem):
return int(self.klass(elem).attr('id')[-1]) - 1
assert self.klass('div', self.html).map(ids_minus_one) == [0, 1]
d = pq('<p>Hello <b>warming</b> world</p>')
self.assertEqual(d('strong').map(lambda i,el: pq(this).text()), [])
开发者ID:NickCis,项目名称:Okeykoclient,代码行数:7,代码来源:test.py
注:本文中的pyquery.pq函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论