国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python3.4編程實現簡單抓取爬蟲功能示例

2020-01-04 16:44:55
字體:
來源:轉載
供稿:網友

本文實例講述了Python3.4編程實現簡單抓取爬蟲功能。分享給大家供大家參考,具體如下:

import urllib.requestimport urllib.parseimport reimport urllib.request,urllib.parse,http.cookiejarimport timedef getHtml(url):  cj=http.cookiejar.CookieJar()  opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))  opener.addheaders=[('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36'),('Cookie','4564564564564564565646540')]  urllib.request.install_opener(opener)  page = urllib.request.urlopen(url)  html = page.read()  return html#print ( html)#html = getHtml("http://weibo.com/")def getimg(html):  html = html.decode('utf-8')  reg='"screen_name":"(.*?)"'  imgre = re.compile(reg)  src=re.findall(imgre,html)  return src#print ("",getimg(html))uid=['2808675432','3888405676','2628551531','2808587400']for a in list(uid):  print (getimg(getHtml("http://weibo.com/"+a)))  time.sleep(1)

希望本文所述對大家Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 壶关县| 焉耆| 陕西省| 宿迁市| 阿尔山市| 交口县| 克拉玛依市| 南平市| 中卫市| 满洲里市| 富民县| 太仆寺旗| 邯郸县| 河津市| 台江县| 鹤山市| 西充县| 静安区| 富川| 弥渡县| 宁安市| 钦州市| 高平市| 保定市| 美姑县| 虎林市| 博湖县| 探索| 获嘉县| 密云县| 隆化县| 民和| 昆明市| 邵阳市| 清远市| 历史| 怀宁县| 鄄城县| 定日县| 承德市| 花莲县|