Python URL和目标列表
我正在尝试创建一个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
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)