fix: Fix article pages returning no content

Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
Skylar "The Cobra" Widulski 2023-06-08 01:38:10 -04:00
parent 16f3ae2903
commit 8428d81708
Signed by: cobra
GPG Key ID: 4FD8F812083FF6F9
2 changed files with 19 additions and 21 deletions

38
main.py
View File

@ -130,29 +130,27 @@ def project_list(path, head, sort=''):
data = requests.get("https://www.instructables.com" + path)
if data.status_code != 200:
return Response(render_template(str(data.status_code) + ".html"), status=data.status_code)
print(data.text)
head = f"{head + ' ' if head != '' else ''}Projects" + sort
path_ = path.rsplit('/', 1)[0]
soup = BeautifulSoup(data.text, "html.parser")
ibles = []
for ible in soup.select("div.category-projects-list div.category-projects-ible"):
link = ible.a["href"]
img = proxy(ible.select("a noscript img")[0].get("src"))
for ible in soup.select("div[class^=cards__] div[class^=ibleCard__]"):
print(ible)
link = ible.select("div a")[0].get("href")
img = proxy(ible.select("div a img")[0].get("src"))
info = ible.select("div.category-projects-ible-info")[0]
title = info.select("strong a.ible-title")[0].text
author = info.select("span.ible-author a")[0].get("href")
author_link = info.select("span.ible-author a")[0].text
channel = info.select("span.ible-channel a")[0].get("href")
channel_link = info.select("span.ible-channel a")[0].text
info = ible.select("div div[class^=description__]")[0]
title = info.select("strong a[^=title__]")[0].text
author = info.select("a")[0].get("href")
author_link = info.select("a")[0].text
channel = info.select("a")[1].get("href")
channel_link = info.select("a")[1].text
stats = ible.select("div.ible-stats")[0]
views = 0
if stats.select("span.ible-views") != []:
views = stats.select("span.ible-views")[0].text
favorites = 0
if stats.select("span.ible-favorites") != []:
favorites = stats.select("span.ible-favorites")[0].text
stats = ible.select("div[class^=footer__] div[class^=stats__]")[0]
views = stats.select("div")[1].text
favorites = stats.select("div")[0].text
ibles.append([link, img, title, author, author_link, channel, channel_link, views, favorites])
@ -457,9 +455,9 @@ def route_article(article):
if stats.select(".favorite-count") != []:
favorites = stats.select(".favorite-count")[0].text
if soup.select("div.main-content") != []:
if soup.select("div.article-body") != []:
## Instructables
body = soup.select("div.main-content")[0]
body = soup.select("div.article-body")[0]
steps = []
for step in body.select("section.step"):
@ -469,10 +467,10 @@ def route_article(article):
step_imgs.append([proxy(img.get("src")), img.get("alt")])
step_text = str(step.select("div.step-body")[0])
step_text = step_text.replace("https://content.instructables.com", "/proxy/?url=https://content.instructables.com")
step_text = step_text.replace("https://content.instructables.com", "/proxy/?url=https://content.instructables.com").replace("https://instructables.com", "").replace("https://www.instructables.com", "")
steps.append([step_title, step_imgs, step_text])
comments = body.select("section.discussion")[0]
comments = soup.select("div.instructable div.bottom-content section.discussion")[0]
comment_count = comments.select("h2")[0].text
comment_list = comments.select("div.posts")

View File

@ -1,6 +1,6 @@
<style>
body {
font-family: DejaVu Sans Mono, monospace;
font-family: Fira Sans, Liberation Sans, sans-serif;
margin:20px auto;
line-height:1.5em;
font-size:1.1em;