Skip to content

Instantly share code, notes, and snippets.

@zhexuany
Created December 1, 2017 23:59
Show Gist options
  • Save zhexuany/1f9471487f968dc43234bde967327b2b to your computer and use it in GitHub Desktop.
Save zhexuany/1f9471487f968dc43234bde967327b2b to your computer and use it in GitHub Desktop.
It is a simple python script which help you grab all leetcode problem by tags.
import requests
import bs4
root_url = 'http://leetcode.com'
index_url = root_url + '/tag/dynamic-programming/'
def get_problem_number_by_tags():
response = requests.get(index_url)
soup = bs4.BeautifulSoup(response.text, "html5lib")
table = soup.find('table')
table_body = table.find('tbody')
rows = table_body.find_all('tr')
data = ""
for row in rows:
cols = row.find_all('td')
cols = [ele.text.strip() for ele in cols]
# data.append([ele for ele in cols if ele]) # Get rid of empty values
# data.append([cols[1]])
data += cols[1]
data += "\n"
return data
print(get_problem_number_by_tags())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment