Skip to content

Instantly share code, notes, and snippets.

@prashantpandey10
Created November 12, 2018 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prashantpandey10/74af5db9fd7f0e0c7474eb8c27b97ffe to your computer and use it in GitHub Desktop.
Save prashantpandey10/74af5db9fd7f0e0c7474eb8c27b97ffe to your computer and use it in GitHub Desktop.
from bs4 import BeautifulSoup
import requests
r = requests.get("https://news.ycombinator.com/")
data = r.text
soup = BeautifulSoup(data)
soup = soup.find("table",{"class":"itemlist"})
tr = soup.find_all('tr');
finalResult = []
for i in xrange(0,len(tr),3):
singleLink = []
link = tr[i].find("a",{"class":"storylink"})
score = tr[i+1].find("span",{"class":"score"})
if(score == None or link == None):
continue
singleLink.append(score['id'])
singleLink.append(link.string.encode("utf-8"))
singleLink.append(link['href'])
singleLink.append(score.string.encode("utf-8"))
finalResult.append(singleLink)
print(finalResult)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment