I am trying to create an app that would allow a person to get a list of GitHub repositories relevant to the search keywords they provide. On the result page for the search query the repositories have a special div class, namely:
<div class="f4 text-normal">
</div>
How to make the Beautiful Soup iterate through all of these classes on the page and then through all the <a> tags in search for hrefs?
For now I only have an idea how to get all the hrefs from <a>s:
import requests, sys, webbrowser, bs4
#variables
linkList = []
#handle input
print('Your GitHub repository search query:')
userInput = input()
#get the results from the URL
results = requests.get('https://github.com/search?q=' + userInput + '&type=repositories'
+ ' '.join(sys.argv[1:]))
results.raise_for_status()
soup = bs4.BeautifulSoup(results.text, 'html.parser')
#find all the viable URLs
data = soup.find_all('a')
for aHref in data:
if "href" in str(aHref):
linkList.append(aHref)
print(linkList)