Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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-针对多个get请求循环使用变量_Python_Web Scraping_Python Requests - Fatal编程技术网

Python-针对多个get请求循环使用变量

Python-针对多个get请求循环使用变量,python,web-scraping,python-requests,Python,Web Scraping,Python Requests,我正试图在多个活动日期间获得门票 每个事件日期都有自己的eventID,因此对于23个可能的日期,eventID为1001-1023 我已经开始手动执行此操作,下面给出了给定日期的所有可用座位,但重复此操作22次并不是最有效的方法 import requests import json f = open('tickets.txt','a') r = requests.get('https://www.website.com/events/1000/tickets/seatmap?secti

我正试图在多个活动日期间获得门票

每个事件日期都有自己的eventID,因此对于23个可能的日期,eventID为1001-1023

我已经开始手动执行此操作,下面给出了给定日期的所有可用座位,但重复此操作22次并不是最有效的方法

import requests
import json 

f = open('tickets.txt','a')

r = requests.get('https://www.website.com/events/1000/tickets/seatmap?sectionid=3')
d = json.loads(r.text)
zones = d['zones']
for key, value in zones.iteritems() :
    print >>f, (key, value)
我想循环使用EventID,一次打印所有日期的所有可用性。但是,我在建立请求/URL时遇到了问题。到目前为止,我已经创建了:

eventIDs =  range(1001, 1023)
baseurl = "https://www.website.com/events/"
sectionId = "/tickets/seatmap?sectionId=3"
更新:我想我已经做到了,我认为这是可行的

for i in eventIDs:
    url=baseurl+str(i)+sectionId
    r = requests.get(url) 
    d = json.loads(r.text)
    print >>f, (d)

这是最好的方法吗?非常感谢您的帮助。谢谢请求-ish样式,可以使用:


或者,您可以将
asyncio
与一起使用。如果你对它感兴趣并想看看它的样子,你可以访问

< P>你应该考虑让你的休息电话异步。如果要坚持使用
请求
-ish样式,可以使用:


或者,您可以将
asyncio
与一起使用。如果您对它感兴趣并想查看它的外观,您可以访问

您可以使用多处理模块中的Pool.map函数来并行查询URL。我认为您总体上做得很好。您可以使用多处理模块中的Pool.map函数来并行查询URL。我认为你总体上做得很好。
# Python3
import grequests

event_ids =  range(1001, 1023)
base_url = "https://www.website.com/events/"
section_id = "/tickets/seatmap?sectionId=3"
# Create an array of urls
urls = [base_url + str(i) + section_id for i in event_ids ]
# Preapare requests
rs = (grequests.get(u) for u in urls)
# Send them
results = grequests.map(rs)