This question already has an answer here:
I want to scrape the href of every project from the website https://www.kickstarter.com/discover/advanced?category_id=16&woe_id=23424829&sort=magic&seed=2449064&page=1 with Python 3.5 and BeautifulSoup.
That's my code
#Loading Libraries
import urllib
import urllib.request
from bs4 import BeautifulSoup
#define URL for scraping
theurl = "https://www.kickstarter.com/discover/advanced?category_id=16&woe_id=23424829&sort=magic&seed=2449064&page=1"
thepage = urllib.request.urlopen(theurl)
#Cooking the Soup
soup = BeautifulSoup(thepage,"html.parser")
#Scraping "Link" (href)
project_ref = soup.findAll('h6', {'class': 'project-title'})
project_href = [project.findChildren('a')[0].href for project in project_ref if project.findChildren('a')]
print(project_href)
I get [None, None, .... None, None] back. I need a list with all the href from the class .
Any ideas?
Try something like this:
This will return all the
href
instances. As i see in your link, a lot ofhref
tags have#
inside them. You can avoid these with a simple regex for proper links, or just ignore the#
symboles.This will still give you some trash links like
/discover?ref=nav
, so if you want to narrow it down use a proper regex for the links you need.EDIT:
To solve the problem you mentioned in the comments: