很久以前,python2的時候,簡單的弄過一點爬蟲程式,後來,到3之後,發現之前的好多程式都特麼不能用了,最最基本的抓頁面都不行了,就重新寫了乙個。
python2縮寫版,大概是這樣的,忘記了沒驗證
import urllib2
response = urllib2.urlopen('')
html = response.read()
print html
python3詳細版
import urllib.request
request = urllib.request.request('')
response = urllib.request.urlopen(request)
if response.getcode() != 200:
print("none!")
else:
html = response.read()
# 如果返回結果不為空
if html is
notnone:
# 還必須編碼,不然格式不對
html = html.decode("utf-8")
print(html)
else:
print("maybe the program is error!")
# 頭資訊
print(response.info())
centos下保留python2安裝python3
1.安裝依賴環境 yum y install zlib devel bzip2 devel openssl devel ncurses devel sqlite devel readline devel tk devel gdbm devel db4 devel libpcap devel xz d...
centos下保留python2安裝python3
1.安裝依賴環境 yum y install zlib devel bzip2 devel openssl devel ncurses devel sqlite devel readline devel tk devel gdbm devel db4 devel libpcap devel xz d...
python網路爬蟲從入門到實戰開發
1 簡單的抓取網頁 from urllib import request req request.request response request.urlopen req html response.read html html.decode utf 8 print html 2 這裡補充點post...