29 lines
1.2 KiB
Lua
29 lines
1.2 KiB
Lua
local WEBSITE_NAME = "TechCrunch"
|
|
local WEBSITE_HOME = "https://techcrunch.com"
|
|
|
|
add_route("techCrunch", "/TechCrunch")
|
|
|
|
techCrunch = {}
|
|
function techCrunch.route(args)
|
|
local xml = get("http://localhost:8081/feed.xml") -- Get an xml RSS feed
|
|
local rss_parser = Feed() -- Create a new instance of the Feed object
|
|
local feed = rss_parser:new(xml) -- Parse the xml into a feed object
|
|
|
|
sleep(1000)
|
|
|
|
local articles = feed.channel.articles -- Get all of the article objects
|
|
local article = articles[1] -- Get the first article object
|
|
log:info("Title: " .. article.title)
|
|
log:info("Description: " .. article.description)
|
|
|
|
local article_content = get(article.link) -- Get the entire article content
|
|
local html_parser = HtmlParser() -- Create a new instance of the html parser
|
|
html_parser:parse(article_content) -- Parse the article into an html tree
|
|
|
|
local elements = html_parser:select_element('.wp-block-post-content') -- Select the element with the class 'wp-block-post-content'
|
|
local element = elements[1] -- String of the html from the element selected
|
|
article.description = element -- Replace the description with the entire article
|
|
|
|
return feed:render(), feed
|
|
end
|