Skip to content

Instantly share code, notes, and snippets.

@theoctober19th
Created September 14, 2020 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theoctober19th/f9a429c6265363785ad5ce135b1fabec to your computer and use it in GitHub Desktop.
Save theoctober19th/f9a429c6265363785ad5ce135b1fabec to your computer and use it in GitHub Desktop.
#Duration
duration_options = response.css('div.field-name-field-length-of-program').xpath('./descendant::div[contains(@class,"field-item")]/text() | ./descendant::div[contains(@class,"field-item")]/p/text()').getall()
fulltime, parttime = False, False
try:
duration_text = duration_options[0].strip()
except:
duration_text = ''
for duration_option in duration_options:
if 'full' in duration_option.strip().lower():
duration_text = duration_option.strip()
fulltime = True
if 'part' in duration_option.strip().lower():
parttime = True
duration_regex = re.compile(r'\d{1,3}\s(months?)', re.IGNORECASE)
duration_match = re.search(duration_regex, duration_text)
if duration_match:
item['duration'] = duration_match.group()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment