Skip to content

Instantly share code, notes, and snippets.

View p208p2002's full-sized avatar

Philip p208p2002

View GitHub Profile
#include <stdio.h>
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
/** @function main */
Mat equalizeIntensity(const Mat& inputImage)
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int convertToWebSafe(int color) {
//0 51 102 153 204 255
// 25 76 127 178 229
if (color >= 229)
return 255;
def fetchM01(targetUrl, startPage=1, host ='https://www.mobile01.com'):
global FETCH_COUNTER #int
global ARTICLE_INFOS #array
soup=getBsObj(targetUrl+'&p='+str(startPage))
if(soup == 1):
sys.exit(1)
if(soup):
mainContent = soup.select_one('#maincontent')
mainContent = mainContent.select_one('.tablelist.forumlist')
mainContent = mainContent.tbody
def getBsObj(url):
try:
html=urlopen(url)
except:
print('open url fail')
return 1
try:
bsObj=BeautifulSoup(html.read(),'html.parser')
except:
from bs4 import BeautifulSoup
from urllib.request import urlopen
import json
import sys
import re
import io
import time
#def
ARTICLE_NUM = int(input('How many article do you want?(Default:35) ') or 35 )
def fetchM01Article(targetUrl,atPage=1,building = {}, datas=[]):
def totalPageFilter(text):
text = text.replace(" ", "")
text = text.replace("\n", "")
text = text[-(int(len(text)/2)+1):]
rule = re.compile(r"[^0-9]")
text = rule.sub('',text)
if(text == ''):
text = 0
return int(text)
[
{
"Topic": "【心得】iPhone XR 開箱,拍照、螢幕效果比一比!",
"Popularity": 31856,
"ReplyCount": 27,
"Datas": [
{
"At": 0,
"Poster": "科技狗",
"Date": "2019-01-02 12:15",
from bs4 import BeautifulSoup
from urllib.request import urlopen
#func
def getBsObj(url):
try:
html=urlopen(url)
except:
print('open url fail')
return 1
import socket #引入lib
def print_machine_info(): #自訂副程式
host_name = socket.gethostname()
ip_address = socket.gethostbyname(host_name)
print("Host name: %s" %host_name)
print("IP address: %s" %ip_address)
if __name__ == '__main__': #main函式
print_machine_info()
import socket
def get_remote_machine_info():
remote_host = 'www.python.org' #目標host
try: #使用try except做例外處理
print ("IP address of %s: %s" %(remote_host, socket.gethostbyname(remote_host))) #印出結果
except socket.error as err_msg: #如果發生錯誤
print ("%s: %s" %(remote_host, err_msg)) #印出錯誤訊息
if __name__ == '__main__':