Created
November 14, 2020 23:38
-
-
Save RyanGreenup/df6a9a7c35cf5fdd3fe8cae11d02eb23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Refer to: | |
#How to extract meta description from urls using python? - Stack Overflow: | |
#https://stackoverflow.com/questions/38009787/how-to-extract-meta-description-#from-urls-using-python | |
import appex | |
import clipboard | |
def main(): | |
if not appex.is_running_extension(): | |
print( | |
'Taking URL from clipboard because this is not running from the share sheet') | |
url = clipboard.get() | |
print(url) | |
elif appex.is_running_extension(): | |
print('Taking URL from share seet') | |
url = appex.get_url() | |
if not url: | |
print('No input URL found.') | |
return | |
print(url) | |
import requests | |
HTMLPage = requests.get(url) | |
from bs4 import BeautifulSoup | |
# soup = BeautifulSoup(HTMLPage, 'html.parser') | |
# taken from https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.html?highlight=title | |
soup = BeautifulSoup(HTMLPage.text, "html5lib") | |
siteDescription = soup.title.string | |
print(siteDescription) | |
import random | |
fn = random.randint(20, 101) | |
markdownString = """[^fn] | |
[^fn]: [$siteDescription]($url) | |
""" | |
markdownString = "[^" + str(fn) + "]\n\n\n" + "[^" + str( | |
fn) + "]: [" + siteDescription + "](" + url + ")" | |
clipboard.set(markdownString) | |
print(clipboard.get()) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment