{query: query ? keyword to search for on pubmed}
# Crosscompute
query = 'hypnosis'
target_folder = '.'
import requests
from os.path import join
from bs4 import BeautifulSoup
from pandas import DataFrame
url = 'https://www.ncbi.nlm.nih.gov/pubmed/'
# get html from a webpage, using key="term", value=query
r = requests.get(url, dict(term='query'))
# create BeautifulSoup object
soup = BeautifulSoup(r.content, 'lxml')
# get titles of articles from html, titles are the "text" in every class named "title"
tags = soup.findAll(class_='title')
tags[:5]
titles = [t.text for t in tags]
titles[:5]
# create dataframe object, set appropriate column name, export to csv file
df = DataFrame(titles, columns=['Title of Article'])
df
df.to_csv(path, index=False)
path = join(target_folder, 'titles-%s.csv' % query)
print('titles_table_path = %s' % path)