0.0.187
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
			
		||||
# Guan is an open-source python package developed and maintained by https://www.guanjihuan.com/about (Ji-Huan Guan, 关济寰). The primary location of this package is on website https://py.guanjihuan.com. GitHub link: https://github.com/guanjihuan/py.guanjihuan.com.
 | 
			
		||||
 | 
			
		||||
# The current version is guan-0.0.186, updated on December 07, 2023.
 | 
			
		||||
# The current version is guan-0.0.187, updated on December 07, 2023.
 | 
			
		||||
 | 
			
		||||
# Installation: pip install --upgrade guan
 | 
			
		||||
 | 
			
		||||
@@ -3600,6 +3600,28 @@ def count_number_of_import_statements(filename, file_format='.py', num=1000):
 | 
			
		||||
    import_statement_counter = Counter(import_array).most_common(num)
 | 
			
		||||
    return import_statement_counter
 | 
			
		||||
 | 
			
		||||
# 从网页的标签中获取内容
 | 
			
		||||
def get_html_from_tags(link, tags=['title', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'li', 'a']):
 | 
			
		||||
    from bs4 import BeautifulSoup
 | 
			
		||||
    import requests
 | 
			
		||||
    import ssl
 | 
			
		||||
    ssl._create_default_https_context = ssl._create_unverified_context
 | 
			
		||||
    headers = {
 | 
			
		||||
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36'
 | 
			
		||||
    }
 | 
			
		||||
    response = requests.get(link, headers=headers)
 | 
			
		||||
    html = response.text
 | 
			
		||||
    soup = BeautifulSoup(html)
 | 
			
		||||
    all_tags = soup.find_all(tags)
 | 
			
		||||
    content = ''
 | 
			
		||||
    for tag in all_tags:
 | 
			
		||||
        text = tag.get_text().replace('\n', '')
 | 
			
		||||
        if content == '':
 | 
			
		||||
            content = text
 | 
			
		||||
        else:
 | 
			
		||||
            content = content + '\n\n' + text
 | 
			
		||||
    return content
 | 
			
		||||
 | 
			
		||||
# 将RGB转成HEX
 | 
			
		||||
def rgb_to_hex(rgb, pound=1):
 | 
			
		||||
    if pound==0:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user