diff --git a/main.py b/main.py index 313fa64..b679e02 100644 --- a/main.py +++ b/main.py @@ -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") diff --git a/templates/style.html b/templates/style.html index 6c52400..bbccbcb 100644 --- a/templates/style.html +++ b/templates/style.html @@ -1,6 +1,6 @@