Python BeautifulSoup Extracting PHP Links
Question: I'm having a problem in Python with BeautifulSoup. I need to extract all files
on the page that end in ".php", but they also have to be local files. They
can't be from another website. This is what I have so far:

    
    
        from bs4 import BeautifulSoup
        import mechanize
        import sys
    
        url = sys.argv[1]
    
        br = mechanize.Browser()
        code = br.open(url)
        html = code.read()
        soup = BeautifulSoup(html)
    

This is where I get stuck on what to do. I imagine using _soup.findall_ to get
all the "a href" tags.


Answer: Try like this,

    
    
    page=urllib2.urlopen(url)
    soup=BeautifulSoup(page.read())
    
    for a in soup.findAll('a'):
      if a['href'].endswith('.php'):
         print a['href']
    

