爬蟲實戰——麻省理工學院新聞

文章目錄

  • 發現寶藏
  • 一、 目標
  • 二、 淺析
  • 三、獲取所有模塊
  • 四、請求處理模塊、版面、文章
    • 1. 分析切換頁面的參數傳遞
    • 2. 獲取共有多少頁標簽并遍歷版面
    • 3.解析版面并保存版面信息
    • 4. 解析文章列表和文章
    • 5. 清洗文章
    • 6. 保存文章圖片
  • 五、完整代碼
  • 六、效果展示

發現寶藏

前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。【寶藏入口】。

一、 目標

爬取news.mit.edu的字段,包含標題、內容,作者,發布時間,鏈接地址,文章快照 (可能需要翻墻才能訪問)

二、 淺析

1.全部新聞大致分為4個模塊
在這里插入圖片描述

2.每個模塊的標簽列表大致如下

在這里插入圖片描述
3.每個標簽對應的文章列表大致如下

在這里插入圖片描述

4.具體每篇文章對應的結構如下

在這里插入圖片描述

三、獲取所有模塊

其實就四個模塊,列舉出來就好,然后對每個分別解析爬取每個模塊

class MitnewsScraper:def __init__(self, root_url, model_url, img_output_dir):self.root_url = root_urlself.model_url = model_urlself.img_output_dir = img_output_dirself.headers = {'Referer': 'https://news.mit.edu/','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ''Chrome/122.0.0.0 Safari/537.36','Cookie': '替換成你自己的',}...def run():root_url = 'https://news.mit.edu/'model_urls = ['https://news.mit.edu/topic', 'https://news.mit.edu/clp','https://news.mit.edu/department', 'https://news.mit.edu/']output_dir = 'D:\imgs\mit-news'for model_url in model_urls:scraper = MitnewsScraper(root_url, model_url, output_dir)scraper.catalogue_all_pages()

四、請求處理模塊、版面、文章

先處理一個模塊(TOPICS)

1. 分析切換頁面的參數傳遞

如圖可知是get請求,需要傳一個參數page

在這里插入圖片描述

2. 獲取共有多少頁標簽并遍歷版面

實際上是獲取所有的page參數,然后進行遍歷獲取所有的標簽

在這里插入圖片描述

 # 獲取一個模塊有多少版面def catalogue_all_pages(self):response = requests.get(self.model_url, headers=self.headers)soup = BeautifulSoup(response.text, 'html.parser')try:match = re.search(r'of (\d+) topics', soup.text)total_catalogues = int(match.group(1))total_pages = math.ceil(total_catalogues / 20)print('topics模塊一共有' + match.group(1) + '個版面,' + str(total_pages) + '頁數據')for page in range(0, total_pages):self.parse_catalogues(page)print(f"========Finished catalogues page {page + 1}========")except:self.parse_catalogues(0)

3.解析版面并保存版面信息

前三個模塊的版面列表

在這里插入圖片描述

第四個模塊的版面列表

在這里插入圖片描述

 # 解析版面列表里的版面def parse_catalogues(self, page):params = {'page': page}response = requests.get(self.model_url, params=params, headers=self.headers)if response.status_code == 200:soup = BeautifulSoup(response.text, 'html.parser')if self.root_url == self.model_url:catalogue_list = soup.find('div','site-browse--recommended-section site-browse--recommended-section--schools')catalogues_list = catalogue_list.find_all('li')else:catalogue_list = soup.find('ul', 'page-vocabulary--views--list')catalogues_list = catalogue_list.find_all('li')for index, catalogue in enumerate(catalogues_list):# 操作時間date = datetime.now()# 版面標題catalogue_title = catalogue.find('a').get_text(strip=True)print('第' + str(index + 1) + '個版面標題為:' + catalogue_title)catalogue_href = catalogue.find('a').get('href')# 版面idcatalogue_id = catalogue_href[1:]catalogue_url = self.root_url + catalogue_hrefprint('第' + str(index + 1) + '個版面地址為:' + catalogue_url)# 根據版面url解析文章列表response = requests.get(catalogue_url, headers=self.headers)soup = BeautifulSoup(response.text, 'html.parser')match = re.search(r'of (\d+)', soup.text)# 查找一個版面有多少篇文章total_cards = int(match.group(1))total_pages = math.ceil(total_cards / 15)print(f'{catalogue_title}版面一共有{total_cards}篇文章,' + f'{total_pages}頁數據')for page in range(0, total_pages):self.parse_cards_list(page, catalogue_url, catalogue_id)print(f"========Finished {catalogue_title} 版面 page {page + 1}========")# 連接 MongoDB 數據庫服務器client = MongoClient('mongodb://localhost:27017/')# 創建或選擇數據庫db = client['mit-news']# 創建或選擇集合catalogues_collection = db['catalogues']# 插入示例數據到 catalogues 集合catalogue_data = {'id': catalogue_id,'date': date,'title': catalogue_title,'url': catalogue_url,'cardSize': total_cards}catalogues_collection.insert_one(catalogue_data)return Trueelse:raise Exception(f"Failed to fetch page {page}. Status code: {response.status_code}")

4. 解析文章列表和文章

在這里插入圖片描述
在這里插入圖片描述
尋找冗余部分并刪除,例如

在這里插入圖片描述

 # 解析文章列表里的文章def parse_cards_list(self, page, url, catalogue_id):params = {'page': page}response = requests.get(url, params=params, headers=self.headers)if response.status_code == 200:soup = BeautifulSoup(response.text, 'html.parser')card_list = soup.find('div', 'page-term--views--list')cards_list = card_list.find_all('div', 'page-term--views--list-item')for index, card in enumerate(cards_list):# 對應的版面idcatalogue_id = catalogue_id# 操作時間date = datetime.now()# 文章標題card_title = card.find('a', 'term-page--news-article--item--title--link').find('span').get_text(strip=True)# 文章簡介card_introduction = card.find('p', 'term-page--news-article--item--dek').find('span').get_text(strip=True)# 文章更新時間publish_time = card.find('p', 'term-page--news-article--item--publication-date').find('time').get('datetime')updateTime = datetime.strptime(publish_time, '%Y-%m-%dT%H:%M:%SZ')# 文章地址temp_url = card.find('div', 'term-page--news-article--item--cover-image').find('a').get('href')url = 'https://news.mit.edu' + temp_url# 文章idpattern = r'(\w+(-\w+)*)-(\d+)'match = re.search(pattern, temp_url)card_id = str(match.group(0))card_response = requests.get(url, headers=self.headers)soup = BeautifulSoup(card_response.text, 'html.parser')# 原始htmldom結構html_title = soup.find('div', id='block-mit-page-title')html_content = soup.find('div', id='block-mit-content')# 合并標題和內容html_title.append(html_content)html_cut1 = soup.find('div', 'news-article--topics')html_cut2 = soup.find('div', 'news-article--archives')html_cut3 = soup.find('div', 'news-article--content--side-column')html_cut4 = soup.find('div', 'news-article--press-inquiries')html_cut5 = soup.find_all('div', 'visually-hidden')html_cut6 = soup.find('p', 'news-article--images-gallery--nav--inner')# 移除元素if html_cut1:html_cut1.extract()if html_cut2:html_cut2.extract()if html_cut3:html_cut3.extract()if html_cut4:html_cut4.extract()if html_cut5:for item in html_cut5:item.extract()if html_cut6:html_cut6.extract()# 獲取合并后的內容文本html_content = html_title# 文章作者author_list = html_content.find('div', 'news-article--authored-by').find_all('span')author = ''for item in author_list:author = author + item.get_text()# 增加保留html樣式的源文本origin_html = html_content.prettify()  # String# 轉義網頁中的圖片標簽str_html = self.transcoding_tags(origin_html)# 再包裝成temp_soup = BeautifulSoup(str_html, 'html.parser')# 反轉譯文件中的插圖str_html = self.translate_tags(temp_soup.text)# 綁定更新內容content = self.clean_content(str_html)# 下載圖片imgs = []img_array = soup.find_all('div', 'news-article--image-item')for item in img_array:img_url = self.root_url + item.find('img').get('data-src')imgs.append(img_url)if len(imgs) != 0:# 下載圖片illustrations = self.download_images(imgs, card_id)# 連接 MongoDB 數據庫服務器client = MongoClient('mongodb://localhost:27017/')# 創建或選擇數據庫db = client['mit-news']# 創建或選擇集合cards_collection = db['cards']# 插入示例數據到 catalogues 集合card_data = {'id': card_id,'catalogueId': catalogue_id,'type': 'mit-news','date': date,'title': card_title,'author': author,'card_introduction': card_introduction,'updatetime': updateTime,'url': url,'html_content': str(html_content),'content': content,'illustrations': illustrations,}cards_collection.insert_one(card_data)return Trueelse:raise Exception(f"Failed to fetch page {page}. Status code: {response.status_code}")

5. 清洗文章

 # 工具 轉義標簽def transcoding_tags(self, htmlstr):re_img = re.compile(r'\s*<(img.*?)>\s*', re.M)s = re_img.sub(r'\n @@##\1##@@ \n', htmlstr)  # IMG 轉義return s# 工具 轉義標簽def translate_tags(self, htmlstr):re_img = re.compile(r'@@##(img.*?)##@@', re.M)s = re_img.sub(r'<\1>', htmlstr)  # IMG 轉義return s# 清洗文章def clean_content(self, content):if content is not None:content = re.sub(r'\r', r'\n', content)content = re.sub(r'\n{2,}', '', content)content = re.sub(r' {6,}', '', content)content = re.sub(r' {3,}\n', '', content)content = re.sub(r'<img src="../../../image/zxbl.gif"/>', '', content)content = content.replace('<img border="0" src="****處理標記:[Article]時, 字段 [SnapUrl] 在數據源中沒有找到! ****"/> ', '')content = content.replace(''' <!--/enpcontent<INPUT type=checkbox value=0 name=titlecheckbox sourceid="<Source>SourcePh " style="display:none">''','') \.replace(' <!--enpcontent', '').replace('<TABLE>', '')content = content.replace('<P>', '').replace('<\P>', '').replace('&nbsp;', ' ')return content

6. 保存文章圖片

# 下載圖片def download_images(self, img_urls, card_id):# 根據card_id創建一個新的子目錄images_dir = os.path.join(self.img_output_dir, card_id)if not os.path.exists(images_dir):os.makedirs(images_dir)downloaded_images = []for index, img_url in enumerate(img_urls):try:response = requests.get(img_url, stream=True, headers=self.headers)if response.status_code == 200:# 從URL中提取圖片文件名img_name_with_extension = img_url.split('/')[-1]pattern = r'^[^?]*'match = re.search(pattern, img_name_with_extension)img_name = match.group(0)# 保存圖片with open(os.path.join(images_dir, img_name), 'wb') as f:f.write(response.content)downloaded_images.append([img_url, os.path.join(images_dir, img_name)])except requests.exceptions.RequestException as e:print(f'請求圖片時發生錯誤:{e}')except Exception as e:print(f'保存圖片時發生錯誤:{e}')return downloaded_images# 如果文件夾存在則跳過else:print(f'文章id為{card_id}的圖片文件夾已經存在')return []

五、完整代碼

import os
from datetime import datetime
import requests
from bs4 import BeautifulSoup
from pymongo import MongoClient
import re
import mathclass MitnewsScraper:def __init__(self, root_url, model_url, img_output_dir):self.root_url = root_urlself.model_url = model_urlself.img_output_dir = img_output_dirself.headers = {'Referer': 'https://news.mit.edu/','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ''Chrome/122.0.0.0 Safari/537.36','Cookie': '_fbp=fb.1.1708485200443.423329752; _ga_HWFLFTST95=GS1.2.1708485227.1.0.1708485227.0.0.0; ''_hp2_id.2065608176=%7B%22userId%22%3A%228766180140632296%22%2C%22pageviewId%22%3A''%223284419326231258%22%2C%22sessionId%22%3A%228340313071591018%22%2C%22identity%22%3Anull%2C''%22trackerVersion%22%3A%224.0%22%7D; _ga_RP0185XJY9=GS1.1.1708485227.1.0.1708485301.0.0.0; ''_ga_PW4Z02MCFS=GS1.1.1709002375.3.0.1709002380.0.0.0; ''_ga_03E2REYYWV=GS1.1.1709002375.3.0.1709002380.0.0.0; _gid=GA1.2.2012514268.1709124148; ''_gat_UA-1592615-17=1; _gat_UA-1592615-30=1; ''_ga_342NG5FVLH=GS1.1.1709256315.12.1.1709259230.0.0.0; _ga=GA1.1.1063081174.1708479841; ''_ga_R8TSBG6RMB=GS1.2.1709256316.12.1.1709259230.0.0.0; ''_ga_5BGKP7GP4G=GS1.2.1709256316.12.1.1709259230.0.0.0',}# 獲取一個模塊有多少版面def catalogue_all_pages(self):response = requests.get(self.model_url, headers=self.headers)soup = BeautifulSoup(response.text, 'html.parser')try:match = re.search(r'of (\d+) topics', soup.text)total_catalogues = int(match.group(1))total_pages = math.ceil(total_catalogues / 20)print('topics模塊一共有' + match.group(1) + '個版面,' + str(total_pages) + '頁數據')for page in range(0, total_pages):self.parse_catalogues(page)print(f"========Finished catalogues page {page + 1}========")except:self.parse_catalogues(0)# 解析版面列表里的版面def parse_catalogues(self, page):params = {'page': page}response = requests.get(self.model_url, params=params, headers=self.headers)if response.status_code == 200:soup = BeautifulSoup(response.text, 'html.parser')if self.root_url == self.model_url:catalogue_list = soup.find('div','site-browse--recommended-section site-browse--recommended-section--schools')catalogues_list = catalogue_list.find_all('li')else:catalogue_list = soup.find('ul', 'page-vocabulary--views--list')catalogues_list = catalogue_list.find_all('li')for index, catalogue in enumerate(catalogues_list):# 操作時間date = datetime.now()# 版面標題catalogue_title = catalogue.find('a').get_text(strip=True)print('第' + str(index + 1) + '個版面標題為:' + catalogue_title)catalogue_href = catalogue.find('a').get('href')# 版面idcatalogue_id = catalogue_href[1:]catalogue_url = self.root_url + catalogue_hrefprint('第' + str(index + 1) + '個版面地址為:' + catalogue_url)# 根據版面url解析文章列表response = requests.get(catalogue_url, headers=self.headers)soup = BeautifulSoup(response.text, 'html.parser')match = re.search(r'of (\d+)', soup.text)# 查找一個版面有多少篇文章total_cards = int(match.group(1))total_pages = math.ceil(total_cards / 15)print(f'{catalogue_title}版面一共有{total_cards}篇文章,' + f'{total_pages}頁數據')for page in range(0, total_pages):self.parse_cards_list(page, catalogue_url, catalogue_id)print(f"========Finished {catalogue_title} 版面 page {page + 1}========")# 連接 MongoDB 數據庫服務器client = MongoClient('mongodb://localhost:27017/')# 創建或選擇數據庫db = client['mit-news']# 創建或選擇集合catalogues_collection = db['catalogues']# 插入示例數據到 catalogues 集合catalogue_data = {'id': catalogue_id,'date': date,'title': catalogue_title,'url': catalogue_url,'cardSize': total_cards}catalogues_collection.insert_one(catalogue_data)return Trueelse:raise Exception(f"Failed to fetch page {page}. Status code: {response.status_code}")# 解析文章列表里的文章def parse_cards_list(self, page, url, catalogue_id):params = {'page': page}response = requests.get(url, params=params, headers=self.headers)if response.status_code == 200:soup = BeautifulSoup(response.text, 'html.parser')card_list = soup.find('div', 'page-term--views--list')cards_list = card_list.find_all('div', 'page-term--views--list-item')for index, card in enumerate(cards_list):# 對應的版面idcatalogue_id = catalogue_id# 操作時間date = datetime.now()# 文章標題card_title = card.find('a', 'term-page--news-article--item--title--link').find('span').get_text(strip=True)# 文章簡介card_introduction = card.find('p', 'term-page--news-article--item--dek').find('span').get_text(strip=True)# 文章更新時間publish_time = card.find('p', 'term-page--news-article--item--publication-date').find('time').get('datetime')updateTime = datetime.strptime(publish_time, '%Y-%m-%dT%H:%M:%SZ')# 文章地址temp_url = card.find('div', 'term-page--news-article--item--cover-image').find('a').get('href')url = 'https://news.mit.edu' + temp_url# 文章idpattern = r'(\w+(-\w+)*)-(\d+)'match = re.search(pattern, temp_url)card_id = str(match.group(0))card_response = requests.get(url, headers=self.headers)soup = BeautifulSoup(card_response.text, 'html.parser')# 原始htmldom結構html_title = soup.find('div', id='block-mit-page-title')html_content = soup.find('div', id='block-mit-content')# 合并標題和內容html_title.append(html_content)html_cut1 = soup.find('div', 'news-article--topics')html_cut2 = soup.find('div', 'news-article--archives')html_cut3 = soup.find('div', 'news-article--content--side-column')html_cut4 = soup.find('div', 'news-article--press-inquiries')html_cut5 = soup.find_all('div', 'visually-hidden')html_cut6 = soup.find('p', 'news-article--images-gallery--nav--inner')# 移除元素if html_cut1:html_cut1.extract()if html_cut2:html_cut2.extract()if html_cut3:html_cut3.extract()if html_cut4:html_cut4.extract()if html_cut5:for item in html_cut5:item.extract()if html_cut6:html_cut6.extract()# 獲取合并后的內容文本html_content = html_title# 文章作者author_list = html_content.find('div', 'news-article--authored-by').find_all('span')author = ''for item in author_list:author = author + item.get_text()# 增加保留html樣式的源文本origin_html = html_content.prettify()  # String# 轉義網頁中的圖片標簽str_html = self.transcoding_tags(origin_html)# 再包裝成temp_soup = BeautifulSoup(str_html, 'html.parser')# 反轉譯文件中的插圖str_html = self.translate_tags(temp_soup.text)# 綁定更新內容content = self.clean_content(str_html)# 下載圖片imgs = []img_array = soup.find_all('div', 'news-article--image-item')for item in img_array:img_url = self.root_url + item.find('img').get('data-src')imgs.append(img_url)if len(imgs) != 0:# 下載圖片illustrations = self.download_images(imgs, card_id)# 連接 MongoDB 數據庫服務器client = MongoClient('mongodb://localhost:27017/')# 創建或選擇數據庫db = client['mit-news']# 創建或選擇集合cards_collection = db['cards']# 插入示例數據到 catalogues 集合card_data = {'id': card_id,'catalogueId': catalogue_id,'type': 'mit-news','date': date,'title': card_title,'author': author,'card_introduction': card_introduction,'updatetime': updateTime,'url': url,'html_content': str(html_content),'content': content,'illustrations': illustrations,}cards_collection.insert_one(card_data)return Trueelse:raise Exception(f"Failed to fetch page {page}. Status code: {response.status_code}")# 下載圖片def download_images(self, img_urls, card_id):# 根據card_id創建一個新的子目錄images_dir = os.path.join(self.img_output_dir, card_id)if not os.path.exists(images_dir):os.makedirs(images_dir)downloaded_images = []for index, img_url in enumerate(img_urls):try:response = requests.get(img_url, stream=True, headers=self.headers)if response.status_code == 200:# 從URL中提取圖片文件名img_name_with_extension = img_url.split('/')[-1]pattern = r'^[^?]*'match = re.search(pattern, img_name_with_extension)img_name = match.group(0)# 保存圖片with open(os.path.join(images_dir, img_name), 'wb') as f:f.write(response.content)downloaded_images.append([img_url, os.path.join(images_dir, img_name)])except requests.exceptions.RequestException as e:print(f'請求圖片時發生錯誤:{e}')except Exception as e:print(f'保存圖片時發生錯誤:{e}')return downloaded_images# 如果文件夾存在則跳過else:print(f'文章id為{card_id}的圖片文件夾已經存在')return []# 工具 轉義標簽def transcoding_tags(self, htmlstr):re_img = re.compile(r'\s*<(img.*?)>\s*', re.M)s = re_img.sub(r'\n @@##\1##@@ \n', htmlstr)  # IMG 轉義return s# 工具 轉義標簽def translate_tags(self, htmlstr):re_img = re.compile(r'@@##(img.*?)##@@', re.M)s = re_img.sub(r'<\1>', htmlstr)  # IMG 轉義return s# 清洗文章def clean_content(self, content):if content is not None:content = re.sub(r'\r', r'\n', content)content = re.sub(r'\n{2,}', '', content)content = re.sub(r' {6,}', '', content)content = re.sub(r' {3,}\n', '', content)content = re.sub(r'<img src="../../../image/zxbl.gif"/>', '', content)content = content.replace('<img border="0" src="****處理標記:[Article]時, 字段 [SnapUrl] 在數據源中沒有找到! ****"/> ', '')content = content.replace(''' <!--/enpcontent<INPUT type=checkbox value=0 name=titlecheckbox sourceid="<Source>SourcePh " style="display:none">''','') \.replace(' <!--enpcontent', '').replace('<TABLE>', '')content = content.replace('<P>', '').replace('<\P>', '').replace('&nbsp;', ' ')return contentdef run():root_url = 'https://news.mit.edu/'model_urls = ['https://news.mit.edu/topic', 'https://news.mit.edu/clp','https://news.mit.edu/department', 'https://news.mit.edu/']output_dir = 'D:\imgs\mit-news'for model_url in model_urls:scraper = MitnewsScraper(root_url, model_url, output_dir)scraper.catalogue_all_pages()if __name__ == "__main__":run()

六、效果展示

在這里插入圖片描述
在這里插入圖片描述

在這里插入圖片描述
在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/718595.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/718595.shtml
英文地址,請注明出處:http://en.pswp.cn/news/718595.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

jQuery AJAX get() 和 post() 方法—— W3school 詳解 簡單易懂(二十四)

jQuery get() 和 post() 方法用于通過 HTTP GET 或 POST 請求從服務器請求數據。 HTTP 請求&#xff1a;GET vs. POST 兩種在客戶端和服務器端進行請求-響應的常用方法是&#xff1a;GET 和 POST。 GET - 從指定的資源請求數據POST - 向指定的資源提交要處理的數據 GET 基本…

MySQL面試題-日志(答案版)

日志 1、為什么需要 undo log&#xff1f; &#xff08;1&#xff09;實現事務回滾&#xff0c;保障事務的原子性。 事務處理過程中&#xff0c;如果出現了錯誤或者用戶執 行了 ROLLBACK 語句&#xff0c;MySQL 可以利用 undo log 中的歷史數據將數據恢復到事務開始之前的狀態…

ssh無法直接登入Linux超級用戶root(23/3/3更新)

說明&#xff1a;不允許ssh用超級用戶的身份登入是為了安全性&#xff0c;如果只是學習使用對安全性沒啥要求可以按以下操作解除限制 以普通用戶登錄到服務器后&#xff0c;執行以下命令以編輯 SSH 服務器配置文件 /etc/ssh/sshd_config sudo nano /etc/ssh/sshd_config 此時會…

【C++練級之路】【Lv.10】【STL】priority_queue類和反向迭代器的模擬實現

快樂的流暢&#xff1a;個人主頁 個人專欄&#xff1a;《C語言》《數據結構世界》《進擊的C》 遠方有一堆篝火&#xff0c;在為久候之人燃燒&#xff01; 文章目錄 一、仿函數1.1 仿函數的介紹1.2 仿函數的優勢 二、priority_queue2.1 push2.2 pop2.3 top2.4 size2.5 empty 三、…

【3D Slicer】心臟CT圖像分割操作保姆級教程 Cardiac CT image segmentation

心臟CT圖像分割操作流程指南 1 安裝3D Slicer軟件2 打開文件2.1 從File->Add Data->Choose File2.2 直接拖入 3 進行分割操作4 切片填充 Fill between slices5 第二個例子6 數據保存7 打開保存后的文件 1 安裝3D Slicer軟件 方式二選一 1.官網&#xff1a;3D Slicer 2.百…

JNI方案說明和使用方法介紹

JNI簡介 JNI(Java Native Interface)是Java編程語言中用于實現Java代碼與本地(Native)代碼(通常是C或C++代碼)交互的機制。它允許Java應用程序調用本地代碼中的功能,也可以讓本地代碼調用Java類和方法。JNI在Java平臺上實現了Java與其他編程語言的互操作性。(即可互相…

無字母數字rce總結(自增、取反、異或、或、臨時文件上傳)

目錄 自增 取反 異或 或 臨時文件上傳 自增 自 PHP 8.3.0 起&#xff0c;此功能已軟棄用 在 PHP 中&#xff0c;可以遞增非數字字符串。該字符串必須是字母數字 ASCII 字符串。當到達字母 Z 且遞增到下個字母時&#xff0c;將進位到左側值。例如&#xff0c;$a Z; $a;將…

C++知識點總結(23):高級模擬算法

高級模擬算法例題 一、P5661 公交換乘1. 審題2. 思路3. 參考答案 二、P1003 鋪地毯1. 審題2. 參考答案 三、P1071 潛伏者1. 審題2. 思路3. 參考答案 一、P5661 公交換乘 1. 審題 2. 思路 總花費中&#xff0c;地鐵是必須花費的&#xff0c;公交車可能不花錢&#xff08;坐地…

使用VisualDL進行模型訓練和數據可視化

文章目錄 使用VisualDL進行模型訓練和數據可視化1. 環境準備1.1 安裝VisualDL1.2 設置VisualDL 2. 寫入數據并可視化2.1 檢查訓練數據2.2 跟蹤模型訓練2.3 評估模型訓練效果 3. 啟動VisualDL服務4. 總結 使用VisualDL進行模型訓練和數據可視化 VisualDL是飛槳提供的一個可視化…

Java中的Object類詳解

Java中的Object類詳解 1. equals(Object obj)2. hashCode()3. toString()4.getClass()5.notify() 和 notifyAll()6. wait() 和 wait(long timeout)7. clone()8.finalize() Java中的 Object 類是所有類的父類&#xff0c;可以被所有Java類繼承并使用。下面先看下源碼&#xff1a…

google最新大語言模型gemma本地化部署

Gemma是google推出的新一代大語言模型&#xff0c;構建目標是本地化、開源、高性能。 與同類大語言模型對比&#xff0c;它不僅對硬件的依賴更小&#xff0c;性能卻更高。關鍵是完全開源&#xff0c;使得對模型在具有行業特性的場景中&#xff0c;有了高度定制的能力。 Gemma模…

革新商務數據體驗:引領市場的API商品數據接口

在當今商業環境中&#xff0c;革新商務數據體驗對于維持競爭優勢至關重要。API商品數據接口在這一轉型過程中扮演了核心角色&#xff0c;它不僅為企業提供了實時且全面的數據訪問能力&#xff0c;而且還極大地增強了數據的可操作性和決策支持功能。以下是API商品數據接口如何細…

面試數據庫篇(mysql)- 12分庫分表

拆分策略 垂直分庫 垂直分庫:以表為依據,根據業務將不同表拆分到不同庫中。 特點: 按業務對數據分級管理、維護、監控、擴展在高并發下,提高磁盤IO和數據量連接數垂直分表:以字段為依據,根據字段屬性將不同字段拆分到不同表中。 特點: 1,冷熱數據分離 2,減少IO過渡爭…

C語言入門到精通之練習42:畫圖,學用圓畫圓形。

題目&#xff1a;畫圖&#xff0c;學用圓畫圓形。 程序分析&#xff1a;無。 實例 #include <graphics.h> //VC6.0中是不能運行的&#xff0c;要在Turbo2.0/3.0中 int main() { int driver,mode,i; float j1,k1; driverVGA; modeVGAHI; initgraph(&d…

【Micropython基礎】TCP客戶端與服務器

文章目錄 前言一、連接Wifi1.1 創建STA接口1.2 激活wifi接口1.3 連接WIFI1.4 判斷WIFI是否連接1.5 連接WIFI總體代碼 二、創建TCP 客戶端2.1 創建套接字2.2 設置TCP服務器的ip地址和端口2.3 連接TCP服務器2.3 發送數據2.4 接收數據2.5 斷開連接2.6 示例代碼 三、TCP服務器的創建…

批量二維碼的教程和優勢:拓寬應用領域,提升效率與創新

隨著二維碼技術的不斷發展&#xff0c;批量二維碼在多個領域展現出了顯著的優勢&#xff0c;為商業和行業帶來了更多便捷和創新。以下是批量二維碼的一些顯著優勢&#xff1a; 1. 高效快速生成&#xff1a; 批量二維碼一次性生成多個二維碼&#xff0c;相較于逐個生成的方式&…

Linux之進程信號

目錄 一、概念引入 1、生活中的信號 2、Linux中的信號 二、信號處理常見方式 三、信號的產生 1、鍵盤產生信號 2、系統調用接口產生信號 3、軟件條件產生信號 4、硬件異常產生信號 四、信號的保存 相關概念 信號保存——三個數據結構 信號集——sigset_t 信號集操…

超簡單的chatgpt-next-web部署教程!

隨著AI的應用變廣&#xff0c;各類AI程序已逐漸普及&#xff0c;尤其是在一些日常辦公、學習等與撰寫/翻譯文稿密切相關的場景&#xff0c;大家都希望找到一個適合自己的穩定可靠的ChatGPT軟件來使用。 ChatGPT-Next-Web就是一個很好的選擇。它是一個Github上超人氣的免費開源…

Docker基礎教程 - 1 Docker簡介

更好的閱讀體驗&#xff1a;點這里 &#xff08; www.doubibiji.com &#xff09; 1 Docker簡介 Docker是一個強大的容器化平臺&#xff0c;讓你能夠更輕松地構建、部署和運行應用程序。 下面我們來學習 Docker。 1.1 Docker是什么 1 現在遇到的問題 每次部署一臺服務器&…

CSS 入門指南(一)CSS 概述

CSS 概述 CSS 介紹 CSS&#xff08;Cascading Style Sheets&#xff09;通常稱為 CSS 樣式或層疊樣式表&#xff0c;是一種用來為結構化文檔&#xff08;如 HTML 文檔或 XML 應用&#xff09;添加樣式&#xff08;字體、間距和顏色等&#xff09;以及版面的布局等外觀顯示樣式…