Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python URL和目标列表_Python_List_Url - Fatal编程技术网

Python URL和目标列表

Python URL和目标列表,python,list,url,Python,List,Url,我正在尝试创建一个python脚本,在一个站点上刮取一系列子页面,然后将数据输出到一个文件中。不确定如何将变量放入url,然后在列表中循环。这是我到目前为止得到的 import httplib2 h = httplib2.Http('.cache') s = ['one', 'two', 'three'] def getinfo(): response, content = h.request('https-www.example.com/<list items>/inf

我正在尝试创建一个python脚本,在一个站点上刮取一系列子页面,然后将数据输出到一个文件中。不确定如何将变量放入url,然后在列表中循环。这是我到目前为止得到的

import httplib2
h = httplib2.Http('.cache')
s = ['one', 'two', 'three']


def getinfo():
    response, content = h.request('https-www.example.com/<list items>/info', headers={'Connection':'keep-alive'})
    print(content)
    print(response)

for q in range(len(s)):
    getinfo()
导入httplib2
h=httplib2.Http('.cache')
s=['1','2','3']
def getinfo():
响应,content=h.request('https-www.example.com//info',headers={'Connection':'keep-alive'})
打印(内容)
打印(答复)
对于范围内的q(透镜):
getinfo()
使用

试试这个

def getinfo(item):
    response, content = h.request('https-www.example.com/'+ str(item) + '/info', headers={'Connection':'keep-alive'})
    print(content)
    print(response)

for q in s:
    getinfo(q)

也许你需要像这样的东西

import httplib2
h = httplib2.Http('.cache')
s = ['one', 'two', 'three']

def getinfo():
    for elem in s:
        response, content = h.request('https-www.example.com/'+elem+'/info', headers={'Connection':'keep-alive'})
        print(content)
        print(response)

另一个选项是%格式:

def getinfo():
    response, content = h.request('https-www.example.com/%s/info' % subpage, headers={'Connection':'keep-alive'})
    print(content)
    print(response)
def getinfo():
    response, content = h.request('https-www.example.com/%s/info' % subpage, headers={'Connection':'keep-alive'})
    print(content)
    print(response)