How to use the pyquery.PyQuery function in pyquery

To help you get started, we’ve selected a few pyquery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fle / django-multi-email-field / multi_email_field / tests.py View on Github external
def test__render(self):
        w = MultiEmailWidget()
        output = w.render('test', ['foo@foo.fr', 'bar@bar.fr'])
        self.assertEqual(1, len(pq('textarea', output)))
        self.assertEqual(
            pq('textarea', output).text(),
            'foo@foo.fr\nbar@bar.fr')
github gleitz / howdoi / test_howdoi.py View on Github external
def test_get_text_with_multiple_links_test_two(self):
        html = 'For example, if I were to reference <a rel="nofollow noreferrer" href="http://www.apple.com/">apple.com</a> as the subject of a sentence - or to talk about <a rel="nofollow noreferrer" href="http://www.apple.com/">Apple\'s website</a> as the topic of conversation. This being different to perhaps recommendations for reading <a href="https://ux.stackexchange.com/q/14872/6046">our article about Apple\'s website</a>.'
        paragraph = pq(html)
        expected_output = "For example, if I were to reference [apple.com](http://www.apple.com/) as the subject of a sentence - or to talk about [Apple's website](http://www.apple.com/) as the topic of conversation. This being different to perhaps recommendations for reading [our article about Apple's website](https://ux.stackexchange.com/q/14872/6046)."
        actual_output = howdoi.get_text(paragraph)
        self.assertEqual(actual_output, expected_output)
github dev-techmoe / python-dcdownloader / dcdownloader / parser / EhentaiParser.py View on Github external
async def parse_image_list(self, data):
        doc = pq(data)
        img_name = pq(doc('#i2 div')[2]).text().split('.')[0]
        img_url =  doc('#i3 img').attr('src')

        return {
            img_name: img_url
        }
        # return {
        #     'file_name': 'url'
        # }
        pass
github mdgoldberg / sportsref / sportsref / nba / seasons.py View on Github external
    @sportsref.decorators.memoize
    def get_sub_doc(self, subpage):
        """Returns PyQuery object for a given subpage URL.
        :subpage: The subpage of the season, e.g. 'per_game'.
        :returns: PyQuery object.
        """
        html = sportsref.utils.get_html(self._subpage_url(subpage))
        return pq(html)
github roclark / sportsreference / sportsreference / nba / player.py View on Github external
short_field == 'name' or \
               short_field == 'height' or \
               short_field == 'weight' or \
               short_field == 'birth_date' or \
               short_field == 'nationality':
                continue
            field_stats = []
            if type(player_data) == dict:
                for year, data in player_data.items():
                    stats = pq(data['data'])
                    value = self._parse_value(stats, short_field)
                    field_stats.append(value)
            else:
                if short_field == 'box_plus_minus':
                    short_field = 'boxscore_box_plus_minus'
                stats = pq(player_data)
                value = self._parse_value(stats, short_field)
                field_stats.append(value)
            setattr(self, field, field_stats)
github CGAL / cgal / Documentation / html_output_post_processing.py View on Github external
def collect_figure_anchors(i,infos):
  anchor_name=pq(this).attr('id')
  if re.match("fig__.+",anchor_name) != None:
    infos.anchor_map[anchor_name]=infos.next_index
    infos.next_index+=1
github VincentXWD / create-girls-moe-pytorch / src / dataset / Spider / getchu_get_urls.py View on Github external
def get_url_and_date(I: str, O: str, id_data_output_path: str) -> None:
  '''
  Get image url and date.
  Saved in the resource directory with names of `O` and `id_data_output_path`.
  :param I:
  :param O:
  :param id_data_output_path:
  :return: None
  '''
  with open(I, encoding='utf-8') as fin:
    doc = pyquery.PyQuery(fin.read())
  table = doc.attr('id', 'query_result_main')('tbody')
  id_data = []
  with open(O, 'w', encoding='utf-8') as fout:
    for line in table.items():
      for tr in line('tr').items():
        lst = re.findall(ID_PATTERN, tr.text())
        data = re.findall(DATA_PATTERN, tr.text())
        if len(lst) == 0:
          continue
        fout.write('http://www.getchu.com/soft.phtml?id={}&gc=gc\n'.format(lst[-1]))
        id_data.append([lst[-1], data[-1]])
  with open(id_data_output_path, 'w', encoding='utf-8') as fout:
    for each in id_data:
      fout.write('{} {}\n'.format(each[0], each[1]))
github fungusakafungus / cloudformation-jsonschema / update_parameter_types.py View on Github external
def parse_parameters():
    parameters_href = tools.BASE + 'parameters-section-structure.html'
    h = tools.get_pq(parameters_href)
    dl = h('#main-col-body .variablelist dl').eq(0)
    dl = q(dl)
    dl = zip(dl.children('dt'), dl.children('dd'))
    dl = OrderedDict((q(dt).text(), q(dd)) for dt, dd in dl)
    result = OrderedDict()
    result['Type'] = parse_paremeter_types(dl.pop('Type'))
    for dt in dl.keys():
        result[dt] = {'type': 'string'}
    result['AllowedValues']['type'] = 'array'
    result['NoEcho']['type'] = ['string', 'boolean']
    return result
github bwhite / picarus / server / hadoop_parse.py View on Github external
def fetch_config(server, jobid):
    tree = etree.HTML(requests.get(server + '/jobconf.jsp?jobid=' + jobid).content)
    pq = pyquery.PyQuery(tree)
    try:
        return parse_config(pq)
    except:
        pass
github Germey / Weixin / spider.py View on Github external
def parse_index(html):
    doc = pq(html)
    items = doc('.news-box .news-list li .txt-box h3 a').items()
    for item in items:
        yield item.attr('href')