本文整理汇总了Python中pyquery.PyQuery.eq方法的典型用法代码示例。如果您正苦于以下问题:Python PyQuery.eq方法的具体用法?Python PyQuery.eq怎么用?Python PyQuery.eq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyquery.PyQuery
的用法示例。
在下文中一共展示了PyQuery.eq方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_user_events
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import eq [as 别名]
def get_user_events(data):
user_events = {}
query = PyQuery(data)("#platnosci")("table")("tr")
print(query.eq(0))
for iter, row in enumerate(query):
row_data = {}
row_data["title"] = str(query.eq(iter)("td").eq(0)("a").html()).replace(r"<br />", ";")
row_data["sign_in_url"] = query.eq(iter)("td").eq(0)("a").attr("href")
row_data["edit_url"] = query.eq(iter)("td").eq(2)("a").attr("href")
row_data["state"] = query.eq(iter)("td").eq(1).text()
user_events[iter] = row_data
return user_events
示例2: pullSubmissions
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import eq [as 别名]
def pullSubmissions(subredditName):
html = urllib2.urlopen("http://reddit.com/r/%s" % subredditName).read()
storyObjects = PyQuery(html)(".entry")
for storyObject in [storyObjects.eq(i) for i in range(len(storyObjects))]:
title = storyObject.find("a.title").html()
url = storyObject.find("a.title").attr.href
redditURL = storyObject.find("a.comments").attr.href
if (
redditURL
): # advertisement submissions have no comments page and thus the property is None (NOT TRUE ANYMORE //FIXME)
yield (title, url, redditURL)
示例3: extractCourse
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import eq [as 别名]
def extractCourse(commentsHTML):
c = Course()
table = PyQuery(commentsHTML).find("table.plaintable").children()
c.id = table.eq(0).text().split()[-1]
c.subject_code, c.crse = table.eq(1).text().split()[0].split('-')
c.title = ' '.join(table.eq(1).text().split()[1:])
c.description = table.eq(2).children().eq(1).text()
if c.description == "Description Not Found":
c.description = None
mtimesPQ = table.eq(3).children().eq(1).children().children()
if mtimesPQ.eq(1).children().length > 2:
mtime = MeetingTime()
mtime.days = mtimesPQ.eq(1).children().eq(1).text().split()
mtime.begin = mtimesPQ.eq(1).children().eq(2).text()
mtime.end = mtimesPQ.eq(1).children().eq(3).text()
mtime.location = mtimesPQ.eq(1).children().eq(4).text()
c.exam = mtimesPQ.eq(1).children().eq(5).text()
if mtime.days == ['(ARR)']:
mtime.days = None
mtime.begin = None
c.exam = mtime.location
mtime.location = mtime.end
mtime.end = None
c.meeting_times.append(mtime)
for i in xrange(mtimesPQ.length - 2): # get additional times
mtime = MeetingTime()
mtime.days = mtimesPQ.eq(i).children().eq(5).text().split()
mtime.begin = mtimesPQ.eq(i).children().eq(6).text()
mtime.end = mtimesPQ.eq(i).children().eq(7).text()
mtime.location = mtimesPQ.eq(i).children().eq(8).text()
c.meeting_times.append(mtime)
sectionInfoPQ = table.eq(4).find("table").children().eq(2).children()
c.instructor = sectionInfoPQ.eq(0).text()
c.type = sectionInfoPQ.eq(1).text()
c.status = sectionInfoPQ.eq(2).text()
c.capacity = sectionInfoPQ.eq(3).text()
comments = table.eq(5).children().eq(1).text()
if comments == 'None':
c.comments = None
else:
c.comments = comments
return c
示例4: replace_image
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import eq [as 别名]
def replace_image(self, target, image_name):
elements = self.html_obj('*').filter('[dzid="' + target + '"]')
location = self.location + urllib.quote_plus(image_name)
for e in elements:
pq = PyQuery(e)
if pq.eq(0).is_('img'):
pq.attr('src', location)
else:
pq.css('background-image', 'url("' + location + '");')
return location
return None
示例5: scrape_grants_for_fy
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import eq [as 别名]
def scrape_grants_for_fy(year):
b.open(PAST_GRANTS_URL)
try:
b.select_form(name="Form1")
b["oUcStartDate$ddlDay"] = ["1"]
b["oUcStartDate$ddlMonth"] = ["4"]
b["oUcStartDate$ddlYear"] = [str(year)]
b["oUcEndDate$ddlDay"] = ["31"]
b["oUcEndDate$ddlMonth"] = ["3"]
b["oUcEndDate$ddlYear"] = [str(year + 1)]
resp = b.submit()
except mechanize._form.ItemNotFoundError:
print("ERROR: could not submit form. This usually means you're "
"trying to scrape for a year that doesn't exist "
"on the GOTW website.", file=sys.stderr)
raise
page = PyQuery(resp.read())
for r in page("table tr:not(.GridHeader)"):
grant = {}
anchors = PyQuery(r).find('a')
grant['id'] = anchors.eq(0).attr.title
grant['title'] = anchors.eq(0).text()
grant['pi'] = pi = {}
pi['id'] = util.extract_id(anchors.eq(1).attr.href, 'Person')
pi['name'] = anchors.eq(1).text()
grant['organisation'] = org = {}
org['id'] = util.extract_id(anchors.eq(2).attr.href, 'Organisation')
org['name'] = anchors.eq(2).text()
grant['department'] = dept = {}
dept['id'] = util.extract_id(anchors.eq(3).attr.href, 'Department')
dept['name'] = anchors.eq(3).text()
value = PyQuery(r).find('span').eq(0).attr.title
grant['value'] = util.extract_monetary_value(value)
yield grant
示例6: search_status
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import eq [as 别名]
def search_status(self, keyword, max_length=20):
url = 'http://browse.renren.com/s/status?offset=0&sort=1&range=0&q=%s&l=%d' % (keyword, max_length)
r = self.session.get(url, timeout=5)
status_elements = PyQuery(r.text)('.list_status .status_content')
id_pattern = re.compile("forwardDoing\('(\d+)','(\d+)'\)")
results = []
for index, _ in enumerate(status_elements):
status_element = status_elements.eq(index)
# 跳过转发的
if status_element('.status_root_msg'):
continue
status_element = status_element('.status_content_footer')
status_time = status_element('span').text()
m = id_pattern.search(status_element('.share_status').attr('onclick'))
status_id, user_id = m.groups()
results.append( (int(user_id), int(status_id), status_time) )
return results
示例7: PyQuery
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import eq [as 别名]
#!/usr/bin/env python
import requests
from pyquery import PyQuery
USER_AGENT = 'Mozilla/5.0'
CG_URL = 'http://www.cordobaguias.com.ar/cotizacion-dolar-en-cordoba.html'
PDB_URL = 'http://www.preciodolarblue.com.ar'
AMBITO_URL = 'http://www.ambito.com/economia/mercados/monedas/dolar/info/?ric=ARSB=C'
headers = {'User-Agent': USER_AGENT}
cg = PyQuery(requests.get(CG_URL, headers=headers).content).find('.cuadroPrecioD').text().replace(' pesos', '')
pdb_tds = PyQuery(requests.get(PDB_URL, headers=headers).content).find('td')
pdb = (pdb_tds.eq(3).text(), pdb_tds.eq(4).text())
ambito = PyQuery(requests.get(AMBITO_URL, headers=headers).content)
print 'cordobaguias | preciodolarblue'
print '-' * 30
print '%s | %s' % (cg, ' / '.join(pdb))
print 'Cueva (Ambito): %.2f | %.2f' % (float(ambito.find('#compra>big').text().replace(',', '.')),
float(ambito.find("#venta>big").text().replace(',', '.')))
示例8: open
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import eq [as 别名]
batch_mode = True
cfg=configparser.RawConfigParser()
cfg.read(os.path.expanduser('~/secured/myukrsib.cfg'))
smtp_host = cfg.get('default','smtp_host')
smtp_user = cfg.get('default','smtp_user')
smtp_secret = cfg.get('default','smtp_secret')
#fname = sys.argv[len(sys.argv)-1]
#f = open(fname,'rb')
q = PyQuery(sys.stdin.read())
tbls = PyQuery(q('form#cardAccountInfoForm').children('table'))
t = tbls.eq(0)('td').eq(1).text().split(':')
available_amount = t[2]
global_own_amount = t[1].split()[0]
t = tbls.eq(2)('td').eq(0).text().split(':')
overdraft = t[1]
t = tbls.eq(2)('td').eq(1).text().split(':')
replenishment = t[1]
t = tbls.eq(2)('td').eq(4).text().split(':')
own_amount = t[1]
t = tbls.eq(2)('td').eq(5).text().split(':')
withdrawal = t[1]
account_ops = []
card_ops = []
holds = []