Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch hang on book list retrieval #75

Merged
merged 1 commit into from
Apr 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions uoftscrapers/scrapers/textbooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def scrape(location='.'):
def retrieve_terms():
html = Scraper.get('%s/buy_courselisting.asp' % Textbooks.host)

if html is None:
return []

listing = BeautifulSoup(html, "html.parser")
terms = listing.find(id='fTerm').find_all('option')[1:]

Expand Down Expand Up @@ -137,7 +140,10 @@ def retrieve_departments(terms):
}

xml = Scraper.get('%s/textbooks_xml.asp' % Textbooks.host,
params=payload, headers=headers)
params=payload, headers=headers, max_attempts=3)

if xml is None:
continue

departments = BeautifulSoup(xml, "xml").find_all('department')
for department in departments:
Expand Down Expand Up @@ -168,7 +174,10 @@ def retrieve_courses(department):
}

xml = Scraper.get('%s/textbooks_xml.asp' % Textbooks.host,
params=payload, headers=headers)
params=payload, headers=headers, max_attempts=3)

if xml is None:
return []

courses = BeautifulSoup(xml, "xml").find_all('course')
for course in courses:
Expand Down Expand Up @@ -196,7 +205,10 @@ def retrieve_sections(course):
}

xml = Scraper.get('%s/textbooks_xml.asp' % Textbooks.host,
params=payload, headers=headers)
params=payload, headers=headers, max_attempts=3)

if xml is None:
return []

sections = BeautifulSoup(xml, "xml").find_all('section')
for section in sections:
Expand All @@ -223,14 +235,16 @@ def retrieve_books(section):
'Referer': '%s/buy_courselisting.asp' % Textbooks.host
}

xml = Scraper.get('%s/textbooks_xml.asp' % Textbooks.host,
params=payload, headers=headers)
html = Scraper.get('%s/textbooks_xml.asp' % Textbooks.host,
params=payload, headers=headers, max_attempts=3)

if html is None:
return []

soup = BeautifulSoup(xml, "html.parser")
soup = BeautifulSoup(html, "html.parser")
books = soup.find_all('tr', {'class': 'book'})

if books == None:
done += 1
return []

for book in books:
Expand Down