0

I have seen similar questions. This one is the most similar that I've found: Python converting a list into a dict with a value of 1 for each key

The difference is that I need the dict keys to be unique and ordered keyword arguments.

I am trying to feed the list of links I've generated through a scraper into a request command. I understand the request.get() function only takes a URL string or kwarg parameters - hence my need to pair the list of links with keyword arguments that are ordered.

terms = (input(str('type boolean HERE -->')))
zipcity = (input(str('type location HERE -->')))

search = driver.find_element_by_id('keywordsearch')
search.click()
search.send_keys('terms')
location = driver.find_element_by_id('WHERE')
location.click()
location.send_keys('zipcity')
clickSearch = driver.find_element_by_css_selector('#buttonsearch-button')
clickSearch.click()

time.sleep(5)

cv = []
cvDict = {}
bbb = driver.find_elements_by_class_name('user-name')

for plink in bbb:
    cv.append(plink.find_element_by_css_selector('a').get_attribute('href'))

    cvDict = {x: 1 for x in cv}
print(cvDict)

SOLVED: (for now). Somehow figured it out myself. That literally never happens. Lucky day I guess!

        cvDict = {'one': cv[:1],
              'tw': cv[:2],
              'thr': cv[:3],
              'fou': cv[:4],
              'fiv': cv[:5],
              'six': cv[:6],
              'sev': cv[:7],
              'eig': cv[:8],
              'nin': cv[:9],
              'ten': cv[:10],
              'ele': cv[:11],
              'twe': cv[:12],
              'thi': cv[:13],
              'fourteen': cv[:14],
              'fifteen': cv[:15],
              'sixteen': cv[:16],
              'seventeen': cv[:17],
              'eighteen': cv[:18],
              'nineteen': cv[:19],
              'twent': cv[:20],
              }
GEOCHET
  • 21,119
  • 15
  • 74
  • 98
  • 1
    It's unclear what the keys are. Give a a list with a few strings, and the resulting dict you expect to get from it. If you have any caveats you specifically have, show them in the example. – kabanus May 19 '17 at 17:39
  • If you want keys to be "ordered keyword arguments", then you don't want a dict... – twalberg May 19 '17 at 18:20
  • @twalberg They're ordered as of Python 3.6. – Arya McCarthy May 19 '17 at 18:38
  • Every time I run the script, it returns 20 href strings (URLs). I'm pulling from a job board. Thereforc, the URLs that are generated into the list are unique to a job seeker's profile. So, I now need to feed these URL's to the requests module to access the data of each profile. It' my understanding they must be in a dict. Correct me if I'm wrong? I will post a snippet of my code, hopefully, that will help. –  May 19 '17 at 18:54
  • Thanks for all the help guys! Got it figured out for now. –  May 19 '17 at 19:44
  • You should post that as the answer and mark it, so future users find it. – Arya McCarthy May 20 '17 at 01:04

0 Answers0