Create weixin.rb

This commit is contained in:
王戈wg
2021-07-27 10:04:28 +08:00
committed by GitHub
parent 1963de42b8
commit 8147da5b21

39
websites/weixin.rb Normal file
View File

@@ -0,0 +1,39 @@
register_website(
name: 'telegraph',
test: -> (uri) {
uri.hostname == 'mp.weixin.qq.com'
},
request: ->(uri) {
uri = if uri.scheme == 'https'
uri
else
uri.scheme = 'https'
URI(uri.to_s)
end
get_with_headers(uri, {})
},
process: -> (html) {
document = Nokogiri::HTML(html)
title = document.css('#activity-name').first.content.strip
author = document.css('#js_name').first.content.strip
content = document.css('#js_content').first
content.traverse{|x|
x.remove_class
x.remove_attribute('id')
x.remove_attribute('style')
if x.name == 'img'
unless x['src']
x['src'] = x['data-src']
end
end
}
{
title: title,
author: author,
content: content.to_html.lines.map(&:strip).join
}
}
)