Created
November 12, 2018 20:05
-
-
Save prashantpandey10/74af5db9fd7f0e0c7474eb8c27b97ffe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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