从请求中获取多个URL

时间:2017-01-19 11:59:57

标签: python python-requests

我一直在尝试使用requests.get

获取多个网址

这是我的代码:

import requests
links=['http://regsho.finra.org/FNSQshvol20170117.txt','http://regsho.finra.org/FNSQshvol20170118.txt']
   for url in links:
     for number in range(1,10):
       page = requests.get(url+str(number))
       print(page.text)

不幸的是,它不会产生任何结果。

有人会介意帮我吗?

3 个答案:

答案 0 :(得分:1)

import requests
links=['http://regsho.finra.org/FNSQshvol20170117.txt','http://regsho.finra.org/FNSQshvol20170118.txt']
for url in links:
    page = requests.get(url)
    print(page.text)

删除for循环。

出:

Date|Symbol|ShortVolume|ShortExemptVolume|TotalVolume|Market
20170117|A|185680|1576|584041|Q
20170117|AA|203741|929|406062|Q
20170117|AAAP|3133|0|13594|Q
20170117|AAC|39417|0|63472|Q
20170117|AADR|1311|0|2627|Q
20170117|AAL|854774|5778|1580018|Q
20170117|AAMC|4450|0|6008|Q
20170117|AAME|3636|200|7186|Q
20170117|AAN|66111|200|118626|Q
20170117|AAOI|359275|1600|603069|Q
20170117|AAON|12291|0|31544|Q
20170117|AAP|71928|0|169905|Q
20170117|AAPL|2935502|68038|9269269|Q

答案 1 :(得分:0)

你可以尝试这样:

import requests

links=['http://regsho.finra.org/FNSQshvol20170117.txt','http://regsho.finra.org/FNSQshvol20170118.txt']

with open('path_file17', 'w') as f1, open('path_file18', 'w') as f2:
    f1.write(requests.get(links[0]).content)
    f2.write(requests.get(links[1]).content)

答案 2 :(得分:0)

要提取数据,您不需要数字范围循环

import requests
links=['http://regsho.finra.org/FNSQshvol20170117.txt','http://regsho.finra.org/FNSQshvol20170118.txt']
for url in links:
   page = requests.get(url)
   print(page.text)