1

Since I am using a for loop to request a URL which changed with a constant number, how can I parsed the variable in?

    total_page = 4
    for y in range (total_page):
        variable = 20*y+1
        base_url = 'https://abcd.com/r='
        url = ''.join([base_url, variable])
        finviz1 = requests.get(url)

However, an error occurred

    url = ''.join([base_url, variable])
TypeError: sequence item 1: expected string or Unicode, int found

How to eliminate the error?

1
  • 1
    variable is an integer, while string.join expects a list of strings. Convert variable to string by variable = str(variable) Commented Apr 3, 2020 at 15:17

1 Answer 1

1

It expects all elements of the array to be a string, whereas you are passing variable as an integer. Convert it into a string before passing it, like this:

url = ''.join([base_url, str(variable)])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.