OrangeEfficiency
OrangeEfficiency

Reputation: 47

Getting multiple URLs from request

I have been trying to get multiple urls using requests.get

Here is my code:

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)

Unfortunately, it does not generate me with any results.

Would anyone mind helping me out?

Upvotes: 2

Views: 15499

Answers (3)

Mohammad Yusuf
Mohammad Yusuf

Reputation: 17074

You can try like so:

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)

Upvotes: 0

宏杰李
宏杰李

Reputation: 12168

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)

remove the for loop.

out:

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

Upvotes: 5

Danny Cullen
Danny Cullen

Reputation: 1832

To just extract the data you do not need the number range loop

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)

Upvotes: 2

Related Questions