Python 網路爬蟲講座 2015/05/30
- 取得連結
- X
- 以電子郵件傳送
- 其他應用程式
爬蟲就是~ 用程式來模仿瀏覽器的使用模式
爬Dcard網站試試看
網頁右鍵->檢查元素-> Network ->Preserve log打開

把這個貼到瀏覽器裡面

看起來很醜
我去裝了JsonView套件


剛剛的Dcard是用GET
所以直接貼網址到瀏覽器上就可以看到資料
但是如果是7-11的



貼上去就沒有QQ
GET vs POST


====================================================
來看看裡面的架構

去seven網站選停車場跟廁所的filter
然後去看
把Form Data view source點一下會看到這串


把這串貼在
commandid=SearchStore&city=%E8%8A%B1%E8%93%AE%E7%B8%A3&town=%E5%A3%BD%E8%B1%90%E9%84%89&roadname=&ID=&StoreName=&SpecialStore_Kind=&isDining=False&isParking=True&isLavatory=True&isATM=False&is7WiFi=False&isIce=False&isHotDog=False&isHealthStations=False&isIceCream=False&isOpenStore=False&isFruit=False&isCityCafe=False&address=
把前面這整串貼到 firefox 的hackbar裡面

去寫個python來抓這些資料
- import requests
- import lxml
- import lxml.etree
- data = {"commandid":"SearchStore","city":"台北市","town":"大安區"}
- res = requests.post("http://emap.pcsc.com.tw/EMapSDK.aspx",data=data)
- print res.content
- elem=lxml.etree.fromstring(res.content)
- elem.xpath("//Address/text()")
- for e in elem.xpath("//Address/text()"):
- print e
阿!忘了encode成UTF-8

最上面加一排 # conding=UTF-8

抓資料成功!!
- 取得連結
- X
- 以電子郵件傳送
- 其他應用程式
留言
張貼留言