# Python Script Issues

**URL:** <https://community.unix.com/t/python-script-issues/328234>\
**Category:** Programming\
**Created:** [May 9, 2013, 2:49pm UTC](https://community.unix.com/t/python-script-issues/328234 "2013-05-09T14:49:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![metallica1973](https://community.unix.com/letter_avatar/metallica1973/32/6_22734026db12803ebb3e059622ac3534.png) [@metallica1973](https://community.unix.com/u/metallica1973)\
**Post date:** [May 9, 2013, 2:49pm UTC](https://community.unix.com/t/python-script-issues/328234/1 "2013-05-09T14:49:02Z")

</div>

Gents,

This is a follow up to my previous post:

> **[Python Newbie Question Regex](https://www.unix.com/shell-programming-and-scripting/217521-python-newbie-question-regex.html)**
>
> 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 ha | The UNIX and Linux Forums

Here the latest function that I am having issues with:

```plaintext
def find_all_flvs(url):
    soup = BeautifulSoup(urllib2.urlopen(url))
    flvs = []
    for link in soup.findAll(onclick=re.compile("doShowCHys=1*")):
        link = str(link)
        #startpos = link.find("lpk4=") + 5
        #endpos = link.find("&amp")
        vidnum = re.findall("(?<==)\d{5,7}", link, re.U)
        vidurl = "http://www.blah.com/home/GetPlayerXML.aspx?lpk4=%s" % vidnum[0]

    for hashval_url in BeautifulSoup(urllib2.urlopen(vidurl)).findAll("flv"):
            flvs.append(hashval_url.text)

    return flvs

```

in that I cant understand why when manually looking at my truple

```plaintext
flvs = []

```

it should have all the urls that were scraped such as:

```plaintext
[u'http://blah.blah.com/secure/courses/94343/f4v_H264/94343_00_01_SC03_welcome.f4v?hashval=1368124621_35861c278ff5c700797b0bf8fc04c554', u'http://blah.blah.com/secure/courses/94343/f4v_H264/94343_00_01_SC03_welcome.f4v?hashval=1368124623_67da0c443fe1b220332f1bd9e50e5d6c'

```

it only adding a single url to the truple:

```plaintext
[u'http://blah.blah.com/secure/courses/94343/f4v_H264/94343_00_01_SC03_welcome.f4v?hashval=1368124621_35861c278ff5c700797b0bf8fc04c554'

```

I have a deep feeling it has to do with my list reference:

```plaintext
vidurl = "http://www.blah.com/home/GetPlayerXML.aspx?lpk4=%s" % vidnum[0]

```

Someone please make me feel stupid.

---

<div class="post-metadata">

**Author:** ![ni2](https://community.unix.com/letter_avatar/ni2/32/6_22734026db12803ebb3e059622ac3534.png) [@ni2](https://community.unix.com/u/ni2)\
**Post date:** [May 10, 2013, 1:09am UTC](https://community.unix.com/t/python-script-issues/328234/2 "2013-05-10T01:09:09Z")

</div>

Hi,

Try printing out vidum, then proceed from there.

```nohighlight
vidnum = re.findall("(?<==)\d{5,7}", link, re.U) 
print vidnum

```

---

<div class="post-metadata">

**Author:** ![metallica1973](https://community.unix.com/letter_avatar/metallica1973/32/6_22734026db12803ebb3e059622ac3534.png) [@metallica1973](https://community.unix.com/u/metallica1973)\
**Post date:** [May 10, 2013, 2:13pm UTC](https://community.unix.com/t/python-script-issues/328234/3 "2013-05-10T14:13:58Z")

</div>

thank you for the reply. It actually turned out to be my nested "for" loop that appeared to be the issue. So from

```nohighlight
def find_all_flvs(url):
    soup = BeautifulSoup(urllib2.urlopen(url))
    flvs = []
    for link in soup.findAll(onclick=re.compile("doShowCHys=1*")):
        link = str(link)
        #startpos = link.find("lpk4=") + 5
        #endpos = link.find("&amp")
        vidnum = re.findall("(?<==)\d{5,7}", link, re.U)
        vidurl = "http://www.blah.com/home/GetPlayerXML.aspx?lpk4=%s" % vidnum[0]

    for hashval_url in BeautifulSoup(urllib2.urlopen(vidurl)).findAll("flv"):
            flvs.append(hashval_url.text)

    return flvs

```

to

```nohighlight
def find_all_flvs(url):
    soup = BeautifulSoup(urllib2.urlopen(url))
    flvs = []
    for link in soup.findAll(onclick=re.compile("doShowCHys=1*")):
        link = str(link)
        #startpos = link.find("lpk4=") + 5
        #endpos = link.find("&amp")
        vidnum = re.findall("(?<==)\d{5,7}", link, re.U)
        vidurl = "http://www.blah.com/home/GetPlayerXML.aspx?lpk4=%s" % vidnum[0]

         for hashval_url in BeautifulSoup(urllib2.urlopen(vidurl)).findAll("flv"):
            flvs.append(hashval_url.text)

    return flvs

```
