I've written a script which when I run parses the link of the item from the left sided menu,then it tracks down each individual links to it's main page. Some links spread through pagination some end in a single page. Whatever the case is, the crawler scrapes name and href of each item. While doing so I came across some duplicates which eventually I shook off using got_already function. The site contains 251 videos and my crawler is able to parse them all. Here is what I have done:
import requests
from lxml import html
got_already=[]
Page_link="http://www.wiseowl.co.uk/videos/"
Blink="http://www.wiseowl.co.uk"
def startpoint(page):
req=requests.Session()
response = req.get(page)
tree = html.fromstring(response.text)
titles = tree.xpath("//ul[@class='woMenuList']//li[@class='woMenuItem']/a/@href")
for title in titles:
if "author" not in title and "year" not in title:
GrabbingData(Blink + title)
midpoint(Blink + title)
def midpoint(links):
req=requests.Session()
response = req.get(links)
tree = html.fromstring(response.text)
for links in tree.xpath("//a[@class='woPagingItem']/@href"):
GrabbingData(Blink + links)
def GrabbingData(url):
req=requests.Session()
response = req.get(url)
tree = html.fromstring(response.text)
for item in tree.xpath("//p[@class='woVideoListDefaultSeriesTitle']"):
title = item.xpath('.//a/text()')[0]
link = item.xpath('.//a/@href')[0]
if title not in got_already:
got_already.append(title)
got_already.append(link)
print(title,link)
startpoint(Page_link)