擅长:python、mysql、java
<p>您可以通过<code>re.split(":? ", "string")</code>提取ID号来覆盖数据样本中的角落案例,然后使用<code>requests</code>构建<code>GET</code>请求。你知道吗</p>
<p>下面的堆栈溢出问题可以提供额外的帮助。<a href="https://stackoverflow.com/questions/17178483/how-do-you-send-an-http-get-web-request-in-python">What is the quickest way to HTTP GET in Python?</a>。有关<code>re</code>和正则表达式的更多信息,请参见<a href="https://docs.python.org/3.4/library/re.html#" rel="nofollow noreferrer">here</a></p>
<pre><code>import re
import requests
data_file = open('data.txt','r') # update to reflect location of your .txt file
your_url = 'https://stackoverflow.com/posts' # update to reflect your target url
req_list =[]
for line in data_file:
temp = re.split(":? ", line)
if len(temp) > 2:
if (temp[0],temp[1]) == ("ID","NUMBERS"):
req_list.append(requests.get(your_url, params={'id': temp[2]}))
print(req_list)
data_file.close()
</code></pre>