0

I am currently working on a program to help manage my comic book collection. I want to take the title, issue number, and grade of each comic in its corresponding list and use the values to fill in the f string portions of a url to get last sale data. So far I can only get it to provide a url with the last three entries of each list. Ideally, it would provide three separate urls.

Example:

titles = ['thor', 'deadpool', 'spider-man']

issues = ['6', '19', '50']

grades = ['9.8', '9.8', '9.0']

phrases = []

for ti, iss, gr in zip(titles, issues, grades):
    phrases.append(ti)
    phrases.append(iss)
    phrases.append(gr)

for terms in phrases:
    soldurl=f"https://www.ebay.com/sch/900/i.html _from=R40&_nkw={ti}+%23{iss}+{gr}&_sacat=900&Certification=CGC&_dcat=900&rt=nc&LH_Sold=1&LH_Complete=1"

Output:

https://www.ebay.com/sch/900/i.html?_from=R40&_nkw=spider-man+%2350+9.0&_sacat=900&Certification=CGC&_dcat=900&rt=nc&LH_Sold=1&LH_Complete=1
Kevin Epps
  • 13
  • 1
  • 1
    Welcome to SO! What's the point of `phrases = []`? You already have `ti, iss, gr` in your first loop, why not build the URL right away? Likely, you'll want to append `soldurl` to a list or do something with it, though, otherwise it'll always point to whatever value it had in the last iteration. – ggorlen Mar 09 '21 at 21:04

2 Answers2

0

Check this:

titles = ['thor', 'deadpool', 'spider-man']

issues = ['6', '19', '50']

grades = ['9.8', '9.8', '9.0']

for ti, iss, gr in zip(titles, issues, grades):

    soldurl=f"https://www.ebay.com/sch/900/i.html _from=R40&_nkw={ti}+%23{iss}+{gr}&_sacat=900&Certification=CGC&_dcat=900&rt=nc&LH_Sold=1&LH_Complete=1"
    print(soldurl)

Output:

https://www.ebay.com/sch/900/i.html _from=R40&_nkw=thor+%236+9.8&_sacat=900&Certification=CGC&_dcat=900&rt=nc&LH_Sold=1&LH_Complete=1
https://www.ebay.com/sch/900/i.html _from=R40&_nkw=deadpool+%2319+9.8&_sacat=900&Certification=CGC&_dcat=900&rt=nc&LH_Sold=1&LH_Complete=1
https://www.ebay.com/sch/900/i.html _from=R40&_nkw=spider-man+%2350+9.0&_sacat=900&Certification=CGC&_dcat=900&rt=nc&LH_Sold=1&LH_Complete=1
ahmadfaraz
  • 224
  • 1
  • 9
0

Something like this might work?

soldurls=["https://www.ebay.com/sch/900/i.html _from=R40&_nkw={ti}+%23{iss}+{gr}&_sacat=900&Certification=CGC&_dcat=900&rt=nc&LH_Sold=1&LH_Complete=1" for ti, iss, gr in zip(titles, issues, grades)]

Should return a list of urls.

Ed OBrien
  • 76
  • 4