Added a webscraping website for Hacker News
This commit is contained in:
parent
5a8ac6ede4
commit
189b4b260c
BIN
Web Development Python Projects/bs4-start/__MACOSX/._bs4-start
Executable file
BIN
Web Development Python Projects/bs4-start/__MACOSX/._bs4-start
Executable file
Binary file not shown.
Binary file not shown.
Binary file not shown.
31
Web Development Python Projects/bs4-start/bs4-start/main.py
Normal file
31
Web Development Python Projects/bs4-start/bs4-start/main.py
Normal file
@ -0,0 +1,31 @@
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
|
||||
response = requests.get("https://appbrewery.github.io/news.ycombinator.com/")
|
||||
yc_web_page = response.text
|
||||
|
||||
soup = BeautifulSoup(yc_web_page, "html.parser")
|
||||
articles = soup.find_all(name="a", class_="storylink")
|
||||
|
||||
article_texts = []
|
||||
article_links = []
|
||||
|
||||
for article_tag in articles:
|
||||
text = article_tag.getText()
|
||||
article_texts.append(text)
|
||||
link = article_tag.get("href")
|
||||
article_links.append(link)
|
||||
|
||||
article_upvotes = [int(score.getText().split()[0]) for score in soup.find_all(name="span", class_="score")]
|
||||
|
||||
largest_number = max(article_upvotes)
|
||||
largest_index = article_upvotes.index(largest_number)
|
||||
|
||||
print(article_texts[largest_index])
|
||||
print(article_links[largest_index])
|
||||
print(article_upvotes[largest_index])
|
||||
|
||||
# print(article_texts)
|
||||
# print(article_links)
|
||||
# print(article_upvotes)
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Angela's Personal Site</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1 id="name">Angela Yu</h1>
|
||||
<p><em>Founder of <strong><a href="https://www.appbrewery.co/">The App Brewery</a></strong>.</em></p>
|
||||
<p>I am an iOS and Web Developer. I love coffee and motorcycles.</p>
|
||||
<hr>
|
||||
<h3 class="heading">Books and Teaching</h3>
|
||||
<ul>
|
||||
<li>The Complete iOS App Development Bootcamp</li>
|
||||
<li>The Complete Web Development Bootcamp</li>
|
||||
<li>100 Days of Code - The Complete Python Bootcamp</li>
|
||||
</ul>
|
||||
<hr>
|
||||
<h3 class="heading">Other Pages</h3>
|
||||
<a href="https://angelabauer.github.io/cv/hobbies.html">My Hobbies</a>
|
||||
<a href="https://angelabauer.github.io/cv/contact-me.html">Contact Me</a>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user