Python Regex List Creation


 
Thread Tools Search this Thread
Top Forums Programming Python Regex List Creation
# 1  
Old 07-29-2015
Python Regex List Creation

Here is a snippet of my code:
Code:
    blahblahblah...
    blah[]
    for link in goodies.soup.find_all('a'):
       blah.append(link.get('href'))
       blah=list(set(blah))

which gives my list of urls. So now I use a regex to search for the relevant urls which I want in a list:
Code:
     for r in blah:
     capture=re.findall(r'https://.*', r)
     print (capture)

which prints the results as:
Code:
    []
    ['https://blah.org/plugins/blahblahblahblah/']
    []
    []
    ['https://blah.org/plugins/blahblahblah/']

What I am trying to do is create a list from these results. When I attempt to do this, I always run into a brickwall:
Code:
    for r in blah:
        capture=re.findall(r'https://.*', r)
        purls=[]
        purls.append(capture)
    purls
    [[]]
    for r in blah:
        capture=re.findall(r'https://.*', r)
        purls=[]
           for a in capture:
               purls.append(a)
    purls
    []

This is the closest thing I could come up with:
Code:
    for r in blah:
         capture=re.findall(r'https://.*', r)
         rolos=capture[:]
         print rolos
    []
    ['https://blah.org/plugins/blahblahblahblah/']
    []
    []
    ['https://blah.org/plugins/blahblahblah/']
    whos
    rolos           list      n=0

But as you can see, it didnt create the list???? What am I doing wrong and how can this be accomplished ?

---------- Post updated at 05:01 PM ---------- Previous update was at 04:34 PM ----------

so it turned out to be the +=, which is the increment operator
Code:
    for r in blah:
      capture=re.findall(r'https://.*', r)
      rolos+=capture[:]

Thanks to dslackw for providing this insane resolution. I still cant believe it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python with Regex and Excel

Hello I have a big excel file for Ticket Data Analysis. The idea is to make meaningful insight from Resolution Field. Now as people write whatever they feel like while resolving the ticket it makes quite a task. 1. They may or may not tag it with something like below within the resolution... (1 Reply)
Discussion started by: radioactive9
1 Replies

2. Shell Programming and Scripting

How can i sort this listing in PYTHON by folder creation?

Is there anything i can do about this code? I need to sort it by folder creation, the newest will be first ... thx :) for dirname in postme: dirname = os.path.abspath(dirname) if dirname: ... (2 Replies)
Discussion started by: ZerO13
2 Replies

3. Shell Programming and Scripting

List creation - Grep a line in a file with a script name

Hi, I have a list file which has script names in them. Some scripts take lists as parameters which inturn have script names. This is basically for sequencing the job run. Eg: List1: test1.ksh test2.ksh test2.lst test3.ksh test3.lst test4.ksh test2.lst: test21.ksh test23.ksh... (7 Replies)
Discussion started by: member2014
7 Replies

4. Shell Programming and Scripting

Python Regex Removing One Too Many...

Well, I'm a python noob and my last post here I was introduced to Regex. I thought this would be easy since I knew Regex with Bash. However, I've been banging my head a while to extract an ip address from ifconfig with this: #!/usr/bin/python import re import subprocess from subprocess... (5 Replies)
Discussion started by: Azrael
5 Replies

5. Programming

Python Reading Individual files and Regex through them

As a newbie to Python, I am trying to write a script in which is will add all the log files (*.log) from within a directory to a list, open the files and search for an ip using a regex and single it out (appending the ip's to the list). So far, I have: import re, os def list_files() content = ... (4 Replies)
Discussion started by: metallica1973
4 Replies

6. Shell Programming and Scripting

Python Newbie Question Regex

I starting teaching myself python and am stuck on trying to understand why I am not getting the output that I want. Long story short, I am using PDB for debugging and here my function in which I am having my issue: import re ... ... ... def find_all_flvs(url): soup =... (1 Reply)
Discussion started by: metallica1973
1 Replies

7. Shell Programming and Scripting

Dynamic case creation based on output list from a command

I am attempting to create a script that would allow me to list all the instances associated with a DB2 and then prompt the user to choose which one to issue the db2profile command against. I use the db2 command db2ilist to get a list of the instances for a particular server, but the number of... (7 Replies)
Discussion started by: slatoms
7 Replies

8. Red Hat

Dynamic case creation based on output list from a command

I am attempting to create a script that would allow me to list all the instances associated with a DB2 and then prompt the user to choose which one to issue the db2profile command against. I use the db2 command db2ilist to get a list of the instances for a particular server, but the number of... (1 Reply)
Discussion started by: slatoms
1 Replies

9. UNIX for Dummies Questions & Answers

List directories with given string, sort by creation date

It is for HP-Unix B.11.31. Requirement: 1. List the directories, which directories name has given particular string. Example: Directories with name "Build" 2. On the output of 1. list the directories by creation date as sort order. I tried with; find . -type d -name "Build*" ... (3 Replies)
Discussion started by: Siva SQL
3 Replies

10. Shell Programming and Scripting

Python Regex

I have the below string and regex. However I cant understand why it works the way it does. IP has been changed for safety ;) String = NowSMS Error Report. Error initializing SMSC Interface 'SMPP - 10.15.8.10:17600'. Interface is not available. Regex = (.+\.)\s(.+) I get two... (1 Reply)
Discussion started by: barney34
1 Replies
Login or Register to Ask a Question