Python BeautifulSoup提取PHP链接
我在Python中使用BeautifulSoup时遇到问题。我需要提取页面上以“.php”结尾的所有文件,但它们也必须是本地文件。他们不可能来自其他网站。这就是我到目前为止所做的:Python BeautifulSoup提取PHP链接,python,python-2.7,beautifulsoup,mechanize,Python,Python 2.7,Beautifulsoup,Mechanize,我在Python中使用BeautifulSoup时遇到问题。我需要提取页面上以“.php”结尾的所有文件,但它们也必须是本地文件。他们不可能来自其他网站。这就是我到目前为止所做的: from bs4 import BeautifulSoup import mechanize import sys url = sys.argv[1] br = mechanize.Browser() code = br.open(url) html = c
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)
这就是我被困在做什么的地方。我想象使用soup.findall获得所有的“a href”标签。像这样尝试
page=urllib2.urlopen(url)
soup=BeautifulSoup(page.read())
for a in soup.findAll('a'):
if a['href'].endswith('.php'):
print a['href']
这是一个好的开始。。。然后在
href
s:)上进行筛选
import glob,os
path=input("Enter Your Path in "" =")+"//"
print path
for i in glob.glob(os.path.join(str(path),"*.php")):
print i