findall

Ansible regex_findall multiple strings

孤街浪徒 提交于 2019-12-11 17:57:30
问题 Cisco IOS routers, doing a "dir", and I want to grab all file names with ".bin" in the name. Example string: Directory of flash0:/ 1 -rw- 95890300 May 24 2015 11:27:22 +00:00 c2900-universalk9-mz.SPA.153-3.M5.bin 2 -rw- 68569216 Feb 8 2019 20:15:26 +00:00 c3900e-universalk9-mz.SPA.151-4.M10.bin 3 -rw- 46880 Oct 25 2017 19:08:56 +00:00 pdcamadeusrtra-cfg 4 -rw- 600 Feb 1 2019 19:36:44 +00:00 vlan.dat 260153344 bytes total (95637504 bytes free) I've figured out how to pull "bin", but I can't

findAll() Not Returning Correct Object Type

不羁岁月 提交于 2019-12-11 08:27:53
问题 ItemTag objects contain an Item object and a Tag object. (These are Java domain objects.) This simple query works as expected. I get back a list ItemTags and can do all the wonderful things that ItemTags are supposed to do: def theTags1 = ItemTag.findAll("from ItemTag b") For example: println(theTags1[0].tag.tag) gives me this as expected: Pilgrim's Progress However, as soon as I add another table to the criteria, instead of getting a list of ItemTags, I just get a list of generic objects. e

Find All text within 1 level in HTML using Beautiful Soup - Python

≯℡__Kan透↙ 提交于 2019-12-10 21:28:48
问题 I need to use beautiful soup to accomplish the following Example HTML <div id = "div1"> Text1 <div id="div2> Text2 <div id="div3"> Text3 </div> </div> </div> I need to do a search over this to return to me in separate instances of a list Text1 Text2 Text3 I tried doing a findAll('div'), but it repeated the same Text multiple times ie it would return Text1 Text2 Text3 Text2 Text3 Text3 回答1: Well, you problem is that .text also includes text from all the child nodes. You'll have to manually get

Extract integers with specific length between separators

会有一股神秘感。 提交于 2019-12-10 16:37:51
问题 Given a list of strings like: L = ['1759@1@83@0#1362@0.2600@25.7400@2.8600#1094@1@129.6@14.4', '1356@0.4950@26.7300@2.9700', '1354@1.78@35.244@3.916#1101@2@40@0#1108@2@30@0', '1430@1@19.35@2.15#1431@3@245.62@60.29#1074@12@385.2@58.8#1109', '1809@8@75.34@292.66#1816@4@24.56@95.44#1076@47@510.89@1110.61'] I need to extract all integers with length 4 between separators # or @ , and also extract the first and last integers. No floats. My solution is a bit overcomplicated - replace with space and

Python - AttributeError: 'NoneType' object has no attribute 'findAll'

寵の児 提交于 2019-12-10 10:26:48
问题 I have written my first bit of python code to scrape a website. import csv import urllib2 from BeautifulSoup import BeautifulSoup c = csv.writer(open("data.csv", "wb")) soup = BeautifulSoup(urllib2.urlopen('http://www.kitco.com/kitco-gold-index.html').read()) table = soup.find('table', id="datatable_main") rows = table.findAll('tr')[1:] for tr in rows: cols = tr.findAll('td') text = [] for td in cols: text.append(td.find(text=True)) c.writerow(text) When I test it locally in my ide called

How do I ensure that re.findall() stops at the right place?

放肆的年华 提交于 2019-12-08 16:51:38
问题 Here is the code I have: a='<title>aaa</title><title>aaa2</title><title>aaa3</title>' import re re.findall(r'<(title)>(.*)<(/title)>', a) The result is: [('title', 'aaa</title><title>aaa2</title><title>aaa3', '/title')] If I ever designed a crawler to get me titles of web sites, I might end up with something like this rather than a title for the web site. My question is, how do I limit findall to a single <title></title> ? 回答1: Use re.search instead of re.findall if you only want one match: >

Issue with finding parent of a particular tag in html using python

守給你的承諾、 提交于 2019-12-08 09:37:40
问题 I am trying to fetch parent element of a particular tag using below mentioned code: # -*- coding: cp1252 -*- import csv import urllib2 import sys import time from bs4 import BeautifulSoup from itertools import islice page1= urllib2.urlopen('http://www.sfr.fr/mobile/telephones?vue=000029&tgp=toutes-les-offres&typesmartphone=se-android&typesmartphone=se-apple&typesmartphone=se-bada&typesmartphone=se-rim-blackberry&typesmartphone=se-windows&p=0').read() soup1 = BeautifulSoup(page1) price_parent

Method chaining generic list extensions

主宰稳场 提交于 2019-12-08 06:27:45
问题 I have a List of a "complex" type - an object with a few string properties. The List itself is a property of another object and contains objects of a variety of types, as shown in this abbreviated class structure: Customer { public List<Characteristic> Characteristics; . . . } Characteristic { public string CharacteristicType; public string CharacteristicValue; } I'd like to be able to collect a List of the values of a given type of Characteristics for the current Customer, which I can do in

Searching on class tags with multiple spaces and wildcards with BeautifulSoup

烈酒焚心 提交于 2019-12-07 17:40:34
问题 I am trying to use BeautifulSoup to find all div containers with the class attribute beginning by "foo bar". I had hoped the following would work: from bs4 import BeautifulSoup import re soup.findAll('div',class_=re.compile('^foo bar')) However, it seems that the class definition is separated into a list, like ['foo','bar'] , such that regular expressions are not able to accomplish my task. Is there a way I can accomplish this task? (I have reviewed a number of other posts, but have not found

Why does re.findall return a list of tuples when my pattern only contains one group?

只愿长相守 提交于 2019-12-07 04:39:47
问题 Say I have a string s containing letters and two delimiters 1 and 2 . I want to split the string in the following way: if a substring t falls between 1 and 2 , return t otherwise, return each character So if s = 'ab1cd2efg1hij2k' , the expected output is ['a', 'b', 'cd', 'e', 'f', 'g', 'hij', 'k'] . I tried to use regular expressions: import re s = 'ab1cd2efg1hij2k' re.findall( r'(1([a-z]+)2|[a-z])', s ) [('a', ''), ('b', ''), ('1cd2', 'cd'), ('e', ''), ('f', ''), ('g', ''), ('1hij2', 'hij'),