Fundamentals 4 min read

How to Capture Multiple URLs with Python’s input() Function

This short tutorial explains how to let users enter two URLs in a single input prompt, split the string with Python’s split() method, and alternatively collect the URLs through multiple input calls, providing clear code examples for each approach.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Capture Multiple URLs with Python’s input() Function

Introduction

A user in a Python discussion group asked how to handle input when entering more than one URL: a single input works for one link, but entering two links causes an error. The goal is to accept two URLs from the user.

Implementation

One solution is to ask the user to input both URLs separated by a comma and then split the string:

#一次调用input函数获取两个网址,用逗号分隔
urls = input("请输入两个网址,用逗号分隔:")

#使用split函数分割输入的字符串
url1, url2 = urls.split(',')

print(f"您输入的第一个网址是:{url1.strip()}")
print(f"您输入的第二个网址是:{url2.strip()}")

Alternatively, you can call input() twice to collect each URL separately:

#第一次调用input函数获取第一个网址
url1 = input("请输入第一个网址:")

#第二次调用input函数获取第二个网址
url2 = input("请输入第二个网址:")

print(f"您输入的第一个网址是:{url1}")
print(f"您输入的第二个网址是:{url2}")

Both approaches successfully retrieve multiple URLs from the user, and the .split(',') method was confirmed to work.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Tutorialinputsplitmultiple URLs
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.