2016年8月3日 星期三

JAVA| JDBC|基礎連接SQLserver、MySQL、Oracle資料庫

材料

JDK環境
Java編輯器
一般數據庫.jar(SQL server|[MySQL]|Oracle


package com.DB_Connection; 

import java.sql.*;
 public class dbConnection {
 public static void main(String [] args) { 
	Connection dbConn=null;
	String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
	String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=MyHotel";
	String userName="sa"; String userPwd="123";
	try { //加載驅動
	Class.forName(driverName); //得到連接
	dbConn=DriverManager.getConnection(dbURL,userName,userPwd); //打印連接結果
	System.out.println("連接數據庫成功");} 
	catch(Exception e){ e.printStackTrace();System.out.print("連接失敗");}
	 /*關閉資源*/		
	finally{
		 try { if(dbConn!=null){dbConn.close();}}
		 catch(Exception e){e.printStackTrace();}
			}
	} 

快遞100 API調用 申請方式13159310439

快遞100 | 查詢API | 授權申請


第一步、自己網站 加入 友情鏈接 以通過審核

快遞查詢 + https://m.kuaidi100.com

快遞查詢


第二步、請填寫表格提交後,半天會寄E-mail給你

2016年6月24日 星期五

BeautifulSoup4

$ pip install beautifulsoup4

BeautifulSoup4中文介紹
https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/

四種用法
Python標準庫
BeautifulSoup(markup, "html.parser")
lxml HTML 解析器
BeautifulSoup(markup, "lxml")
lxml XML 解析器
BeautifulSoup(markup, ["lxml", "xml"])
BeautifulSoup(markup, "xml")
html5lib
BeautifulSoup(markup, "html5lib")

幾個簡單的瀏覽結構化數據的方法:

soup.title
# <title>The Dormouse's story</title>

soup.title.name
# u'title'

soup.title.string
# u'The Dormouse's story'

soup.title.parent.name
# u'head'

soup.p
# <p class="title"><b>The Dormouse's story</b></p>

soup.p['class']
# u'title'

soup.a
# <a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>

soup.find_all('a')
# [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>,
# <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>,
# <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>]

soup.find(id="link3")
# <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>



for link in soup.find_all('a'):
print(link.get('href'))
# http://example.com/elsie
# http://example.com/lacie
# http://example.com/tillie



print(soup.get_text())
# The Dormouse's story
#
# The Dormouse's story
#
# Once upon a time there were three little sisters; and their names were
# Elsie,
# Lacie and
# Tillie;
# and they lived at the bottom of a well.
#
# ...

2016年6月23日 星期四

高鐵POST擷取分析

  • Request URL:https://irs.thsrc.com.tw/IMINT/?wicket:interface=:1:BookingS1Form:1:IFormSubmitListener
  • Request Method:POST

GoogleChrome/開發人員工具/Network \\Headers:

  1. Request URL:https://www.gay-torrents.net/search.php?do=process
  2. Request Method:POST
  1. BookingS1Form:hf:0:
  2. selectStartStation:1
  3. selectDestinationStation:11
  4. trainCon:trainRadioGroup:0
  5. bookingMethod:radio20
  6. toTimeInputField:2016/07/21
  7. toTimeTable:230P
  8. toTrainIDInputField:
  9. backTimeInputField:2016/07/21
  10. backTimeTable:
  11. backTrainIDInputField:
  12. ticketPanel:rows:0:ticketAmount:1F
  13. ticketPanel:rows:1:ticketAmount:0H
  14. ticketPanel:rows:2:ticketAmount:0W
  15. ticketPanel:rows:3:ticketAmount:0E
  16. offPeakTrainSearchContainer:onlyQueryOffPeak:on
  17. homeCaptcha:securityCode:TANF
  18. SubmitButton:開始查詢




  1. Request URL:https://www.gay-torrents.net/search.php?do=process
  2. Request Method:POST

回應的標頭

    1. Cache-Control:private
    2. Content-Encoding:gzip
    3. Content-Length:9324
    4. Content-Type:text/html; charset=UTF-8
    5. Date:Fri, 24 Jun 2016 06:30:11 GMT
    6. Pragma:private
    7. Server:lighttpd/1.4.39


淘寶GET擷取分析

開啟淘寶首頁進行搜尋:皮繩

GoogleChrome/開發人員工具/Network

Headers:

  1. Request URL:
    https://s.taobao.com/search?q=%E7%9A%AE%E7%B9%A9&commend=all&ssid=s5-e&search_type=mall&sourceId=tb.index&area=c2c&spm=a1z02.1.6856637.d4910789
  2. Request Method:GET

發現他是使用 HTTP請求 裡面的GET

Postman可以確認Request URL細節
https://www.getpostman.com/docs/install_mac

打開Jupyter

new 一個Python2的py檔

In[1]:

import requests

res = requests.get("https://s.taobao.com/search?q=%E7%9A%AE%E7%B9%A9&commend=all&ssid=s5-e&search_type=mall&sourceId=tb.index&area=c2c&spm=a1z02.1.6856637.d4910789")

print res.text


chrome套件

SelectorGadget

https://chrome.google.com/webstore/detail/selectorgadget/mhjhnkcfbdhnjickkkdbjoemdmbfginb?hl=zh-TW


用Safari檢閱按右鍵檢視元件更快


在class="grid"的div

有0~43共44個方格子
每個方格子都是一個,data-index="0"中的數字為編號0~43
<div class="item " data-category="auctions" data-index="0">….</div>

圖片
data-spm-anchor-id="a230r.1.14.1"

圖上雙橘按鈕區塊 div.similars
找同款data-spm-anchor-id="a230r.1.14.2"
找相似data-spm-anchor-id="a230r.1.14.3"
價格.g_price strong
幾人收貨:class="deal-cnt"

圖片的屬性:
ClassName= J_ItemPic img

baseURI: "https://s.taobao.com/search?q=%E7%9A%AE%E7%B9%A9&commend=all&ssid=s5-e&search_type=mall&sourceId=tb.index&area=c2c&spm=a1z02.1.6856637.d4910…"

alt 送銀扣蠟皮繩水晶吊墜項鏈掛繩男女手工編織黃金翡翠玉珮黑紅繩子
class J_ItemPic img
id J_Itemlist_Pic_38694171862
data-src//g-search2.alicdn.com/img/bao/uploaded/i4/i3/TB1wDPVFVXXXXX.XFXXXXXXXXXX_!!0-item_pic.jpg
src //g-search2.alicdn.com/img/bao/uploaded/i4/i3/TB1wDPVFVXXXXX.XFXXXXXXXXXX_!!0-item_pic.jpg_460x460Q90.jpg

jupyter notebook ( ipython notebook) mac

開啟 終端機
option+空白鍵 選 iTerm(或 終端機)
安裝 Jupyter
$ pip install jupyter

造 一個 jupyter資料夾
$mkdir Jupyter
切換 至 jupyter資料夾下
$cd Jupyter
iTerm輸入
$jupyter notebook
預設瀏覽器會開啟一個 http://localhost:8888

Requests pip install mac

Requests|URLs擷取套件

python2.7
$ pip install requests

python3
$ pip3 install requests