Advertisement
Guest User

Untitled

a guest
Jan 13th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. def search_experiences():
  2.     print('Experience Vaults')
  3.     experiences = {}
  4.     soup_text = []
  5.     SEARCH_URL = "https://erowid.org/experiences/subs/exp_"
  6.     substance = input('Search>').strip().lower()
  7.     substance = substance[0].upper() + substance[1:]
  8.     category = {'General':SEARCH_URL+substance+'_General.shtml','First Times':SEARCH_URL+substance+'_First_Times.shtml', 'Combonations':SEARCH_URL+substance+'_Combonations.shtml',\
  9.     'Retrospective/Summary':SEARCH_URL+substance+'_Retrospective_I_Summary.shtml', 'Preperation/Recipes':SEARCH_URL+substance+'_Preperation_I_Recipes.shtml',\
  10.     'Difficult Experiences':SEARCH_URL+substance+'_Difficult_Experiences.shtml', 'Bad Trips':SEARCH_URL+substance+'_Bad_Trips.shtml', 'Health Problems': SEARCH_URL+substance+'_Health_Problems.shtml',\
  11.     'Train Wrecks and Distaster Trips':SEARCH_URL+substance+'_Train_Wrecks_Trip_Disasters.shtml', 'Addiction and Habituation':SEARCH_URL+substance+'_Addiction_Habituation.shtml',\
  12.     'Glowing Experiences':SEARCH_URL+substance+'_Glowing_Experiences.shtml', 'Msytical Experiences':SEARCH_URL+substance+'_Mystical_Experiences.shtml', 'Health Benfits':SEARCH_URL+substance+'_Health_Benefits.shtml',\
  13.     'Families':SEARCH_URL+substance+'_Families.shtml', 'Medical Use':SEARCH_URL+substance+'_Medical_Use.shtml','What Was In That?':SEARCH_URL+substance+'_What_Was_in_That.shtml'}
  14.    
  15.     x=1
  16.     for key in category:
  17.         print('[+]',x,'.', key)
  18.         x+=1
  19.     cat = input('Category>').strip()
  20.     if cat == 'exit:':
  21.         sys.exit()
  22.     if cat == "main":
  23.         menu()
  24.    
  25.     #Grab page data -- value of key
  26.     URL = (category[cat])
  27.     data = requests.get(URL)
  28.     content = data.text
  29.     search_soup = BeautifulSoup(content, 'html.parser')
  30.     x = 0
  31.    
  32.     for link in search_soup.find_all('a'):
  33.         print('[+]',x, link.text)
  34.         experiences[x] = link.get('href')
  35.         x += 1
  36.  
  37.     choice = input('Choice>').strip()
  38.     data = requests.get('https://erowid.org'+ str(experiences[int(choice)]))
  39.     content = data.text
  40.     search_soup = BeautifulSoup(content, 'html.parser')
  41.     #for comment in search_soup.find_all(string=lambda text:isinstance(text,Comment)):
  42.      #   print(comment)
  43.  
  44.     soup_text.append(str(search_soup))
  45.     #experience = str(re.search(r"<!-- Start Body -->(.*)<!-- End Body -->",str(soup_text[0])))
  46.     for index in soup_text:
  47.         print(soup_text)
  48.     experience = re.search('<!-- Start Body -->(.*)<!-- End Body -->', soup_text[0])
  49.     print(experience)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement