本文整理汇总了Python中pyquery.pyquery.pq函数的典型用法代码示例。如果您正苦于以下问题:Python pq函数的具体用法?Python pq怎么用?Python pq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pq函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_fn_with_kwargs
def test_fn_with_kwargs(self):
"fn() with keyword arguments."
pq.fn.test = lambda p=1: pq(this).eq(p) # NOQA
S = pq(self.html)
self.assertEqual(S('li').test(0).text(), 'Coffee')
self.assertEqual(S('li').test().text(), 'Tea')
self.assertEqual(S('li').test(p=2).text(), 'Milk')
开发者ID:cherryshawn,项目名称:pyquery,代码行数:7,代码来源:test_pyquery.py
示例2: 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()), []) # NOQA
开发者ID:jimt,项目名称:pyquery,代码行数:7,代码来源:test_pyquery.py
示例3: test_fn_with_kwargs
def test_fn_with_kwargs(self):
"fn() with keyword arguments."
pq.fn.test = lambda p=1: pq(this).eq(p)
S = pq(self.html)
self.assertEqual(S("li").test(0).text(), "Coffee")
self.assertEqual(S("li").test().text(), "Tea")
self.assertEqual(S("li").test(p=2).text(), "Milk")
开发者ID:kisiel,项目名称:pyquery,代码行数:7,代码来源:test_pyquery.py
示例4: test_fn
def test_fn(self):
"Example from `PyQuery.Fn` docs."
fn = lambda: this.map(lambda i, el: pq(this).outerHtml()) # NOQA
pq.fn.listOuterHtml = fn
S = pq(self.html)
self.assertEqual(S('li').listOuterHtml(),
['<li>Coffee</li>', '<li>Tea</li>', '<li>Milk</li>'])
开发者ID:cherryshawn,项目名称:pyquery,代码行数:7,代码来源:test_pyquery.py
示例5: test_replaceWith_with_function
def test_replaceWith_with_function(self):
expected = '''<div class="portlet">
TestimageMy link text
imageMy link text 2
Behind you, a three-headed HTML&dash;Entity!
</div>'''
d = pq(self.html)
d('a').replace_with(lambda i, e: pq(e).html())
val = d.__html__()
assert val == expected, (repr(val), repr(expected))
开发者ID:jimt,项目名称:pyquery,代码行数:10,代码来源:test_pyquery.py
示例6: test_remove
def test_remove(self):
d = pq(self.html)
d("img").remove()
val = d("a:first").html()
assert val == "Test My link text", repr(val)
val = d("a:last").html()
assert val == " My link text 2", repr(val)
开发者ID:kisiel,项目名称:pyquery,代码行数:7,代码来源:test_pyquery.py
示例7: test_filter
def test_filter(self):
assert len(self.klass("div", self.html).filter(".node3")) == 1
assert len(self.klass("div", self.html).filter("#node2")) == 1
assert len(self.klass("div", self.html).filter(lambda i: i == 0)) == 1
d = pq("<p>Hello <b>warming</b> world</p>")
self.assertEqual(d("strong").filter(lambda el: True), [])
开发者ID:kisiel,项目名称:pyquery,代码行数:7,代码来源:test_pyquery.py
示例8: test_unicode
def test_unicode(self):
xml = pq(u("<p>é</p>", 'utf-8'))
self.assertEqual(type(xml.html()), text_type)
if PY3k:
self.assertEqual(str(xml), '<p>é</p>')
else:
self.assertEqual(unicode(xml), u("<p>é</p>", 'utf-8'))
self.assertEqual(str(xml), '<p>é</p>')
开发者ID:acdha,项目名称:pyquery,代码行数:8,代码来源:test_pyquery.py
示例9: test_val_for_textarea
def test_val_for_textarea(self):
d = pq(self.html3)
self.assertEqual(d('textarea').val(), 'Spam')
self.assertEqual(d('textarea').text(), 'Spam')
d('textarea').val('42')
self.assertEqual(d('textarea').val(), '42')
# Note: jQuery still returns 'Spam' here.
self.assertEqual(d('textarea').text(), '42')
开发者ID:kveretennicov,项目名称:pyquery,代码行数:8,代码来源:test_pyquery.py
示例10: _login
def _login(self, email, password):
self._log("Logging in...")
login_page = self._session.get('https://www.fitbit.com/login')
form = pq(login_page.content).find('#loginForm')
action = form.attr('action')
data = dict((i.name, i.value) for i in form.find('input'))
data.update({'email': email, 'password': password})
self._session.post(action, data)
开发者ID:joshsee,项目名称:fitbit-python-scrapper,代码行数:8,代码来源:client.py
示例11: test_get
def test_get(self):
if not HAS_REQUEST:
return
d = pq(u('http://ru.wikipedia.org/wiki/Заглавная_страница', 'utf8'),
method='get')
print(d)
self.assertEqual(d('#n-mainpage a').text(),
u('Заглавная страница', 'utf8'))
开发者ID:jimt,项目名称:pyquery,代码行数:8,代码来源:test_pyquery.py
示例12: test_val_for_multiple_elements
def test_val_for_multiple_elements(self):
d = pq(self.html5)
# "Get" returns *first* value.
self.assertEqual(d('div > *').val(), 'spam')
# "Set" updates *every* value.
d('div > *').val('42')
self.assertEqual(d('#first').val(), '42')
self.assertEqual(d('#second').val(), '42')
self.assertEqual(d('#third').val(), '42')
开发者ID:kveretennicov,项目名称:pyquery,代码行数:9,代码来源:test_pyquery.py
示例13: test_replaceWith
def test_replaceWith(self):
expected = '''<div class="portlet">
<a href="/toto">TestimageMy link text</a>
<a href="/toto2">imageMy link text 2</a>
Behind you, a three-headed HTML&dash;Entity!
</div>'''
d = pq(self.html)
d('img').replace_with('image')
val = d.__html__()
assert val == expected, (repr(val), repr(expected))
开发者ID:jimt,项目名称:pyquery,代码行数:10,代码来源:test_pyquery.py
示例14: test_unicode
def test_unicode(self):
xml = pq(u("<html><p>é</p></html>", "utf-8"))
self.assertEqual(type(xml.html()), text_type)
if PY3k:
self.assertEqual(str(xml), "<html><p>é</p></html>")
self.assertEqual(str(xml('p:contains("é")')), "<p>é</p>")
else:
self.assertEqual(unicode(xml), u("<html><p>é</p></html>", "utf-8"))
self.assertEqual(str(xml), "<html><p>é</p></html>")
self.assertEqual(str(xml(u('p:contains("é")', "utf8"))), "<p>é</p>")
self.assertEqual(unicode(xml(u('p:contains("é")', "utf8"))), u("<p>é</p>", "utf8"))
开发者ID:kisiel,项目名称:pyquery,代码行数:11,代码来源:test_pyquery.py
示例15: test_val_for_select
def test_val_for_select(self):
d = pq(self.html4)
self.assertIsNone(d('#first').val())
self.assertEqual(d('#second').val(), 'eggs')
self.assertIsNone(d('#third').val())
d('#first').val('spam')
d('#second').val('bacon')
d('#third').val('eggs') # Selecting non-existing option.
self.assertEqual(d('#first').val(), 'spam')
self.assertEqual(d('#second').val(), 'bacon')
self.assertIsNone(d('#third').val())
d('#first').val('bacon') # Selecting non-existing option.
self.assertIsNone(d('#first').val())
开发者ID:kveretennicov,项目名称:pyquery,代码行数:13,代码来源:test_pyquery.py
示例16: test_val_for_inputs
def test_val_for_inputs(self):
d = pq(self.html2)
self.assertEqual(d('input[name="spam"]').val(), 'Spam')
self.assertEqual(d('input[name="eggs"]').val(), 'Eggs')
self.assertEqual(d('input:checkbox').val(), 'Bacon')
self.assertEqual(d('input:radio').val(), 'Ham')
d('input[name="spam"]').val('42')
d('input[name="eggs"]').val('43')
d('input:checkbox').val('44')
d('input:radio').val('45')
self.assertEqual(d('input[name="spam"]').val(), '42')
self.assertEqual(d('input[name="eggs"]').val(), '43')
self.assertEqual(d('input:checkbox').val(), '44')
self.assertEqual(d('input:radio').val(), '45')
开发者ID:kveretennicov,项目名称:pyquery,代码行数:14,代码来源:test_pyquery.py
示例17: test_from_url
def test_from_url(url, timeout=1):
"""
get proxy from given url address , and collect proxy and port ; then test them ;
return a list of useful proxy_s
:param url:
:param timeout: second(s) , default 1 second
:return:
usage:
url = 'http://www.ip84.com/pn'
proxy_list = test_from_url(url)
or like this: proxy_list = test_from_url(url , timeout=3)
"""
patt_pp = re.compile(r'(?<![\.\d])(?:\d{1,3}\.){3}\d{1,3}(?![\.\d]):\d{1,5}')
t = requests.get(url, verify=True).text
txt = ':'.join(pq(t).text().split(' '))
proxy_port = list(set(re.findall(patt_pp, txt)))
return test_from_list(proxy_list=proxy_port, timeout=timeout)
开发者ID:yangmingsong,项目名称:python,代码行数:18,代码来源:proxy_test.py
示例18: getbyurl_zh
def getbyurl_zh(url):
map_data={}
import requests
a=requests.get(url).content.decode('gbk')
from pyquery.pyquery import PyQuery as pq
rr={u"题 名":'title',
u"页 码":u'载体形态',
u"作 者":u'作者',
u"出版项":u'出版社',
"ISB":u'标准号',
u"索取号":'position',
u"附注信":u'载体形态'}
for i in pq(a)("tr td"):
print pq(i).text()[:3]
if pq(i).text()[:3] in rr:
map_data[ rr[ pq(i).text()[:3] ] ]= pq(i).text()[pq(i).text().index(":")+1:]
map_data['img']= "http://book.bookday.cn/book/cover?isbn=%s&w=100&h=150" %map_data[u'标准号']
return map_data
开发者ID:beordle,项目名称:jnu.fm,代码行数:18,代码来源:web_book_callback.py
示例19: test_post
def test_post(self):
d = pq(self.application_url, {'q': 'foo'},
method='post')
self.assertIn('REQUEST_METHOD: POST', d('p').text())
self.assertIn('q=foo', d('p').text())
开发者ID:jimt,项目名称:pyquery,代码行数:5,代码来源:test_pyquery.py
示例20: test_remove_namespaces
def test_remove_namespaces(self):
expected = 'What'
d = pq(b(self.xml), parser='xml').remove_namespaces()
val = d('blah').text()
self.assertEqual(repr(val), repr(expected))
开发者ID:jimt,项目名称:pyquery,代码行数:5,代码来源:test_pyquery.py
注:本文中的pyquery.pyquery.pq函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论