Python3.4編程實現(xiàn)簡單抓取爬蟲功能示例
本文實例講述了Python3.4編程實現(xiàn)簡單抓取爬蟲功能。分享給大家供大家參考,具體如下:
import urllib.request
import urllib.parse
import re
import urllib.request,urllib.parse,http.cookiejar
import time
def 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)
更多關(guān)于Python相關(guān)內(nèi)容可查看本站專題:《Python Socket編程技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計有所幫助。
- Python爬蟲實例爬取網(wǎng)站搞笑段子
- Python網(wǎng)絡(luò)爬蟲與信息提取(實例講解)
- python利用urllib實現(xiàn)爬取京東網(wǎng)站商品圖片的爬蟲實例
- python制作小說爬蟲實錄
- python爬蟲實戰(zhàn)之最簡單的網(wǎng)頁爬蟲教程
- Python 爬蟲之超鏈接 url中含有中文出錯及解決辦法
- Python實現(xiàn)的爬蟲功能代碼
- 基于python爬蟲數(shù)據(jù)處理(詳解)
- python爬蟲入門教程--HTML文本的解析庫BeautifulSoup(四)
- Python爬蟲之模擬知乎登錄的方法教程
- python爬蟲入門教程--優(yōu)雅的HTTP庫requests(二)
- Python爬蟲實現(xiàn)(偽)球迷速成
相關(guān)文章
springboot aop方式實現(xiàn)接口入?yún)⑿r灥氖纠a
在實際開發(fā)項目中,我們常常需要對接口入?yún)⑦M行校驗,本文主要介紹了springboot aop方式實現(xiàn)接口入?yún)⑿r灥氖纠a,具有一定的參考價值,感興趣的可以了解一下2023-08-08
解決Tkinter中button按鈕未按卻主動執(zhí)行command函數(shù)的問題
這篇文章主要介紹了解決Tkinter中button按鈕未按卻主動執(zhí)行command函數(shù)的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-05-05
win10環(huán)境下配置vscode python開發(fā)環(huán)境的教程詳解
這篇文章主要介紹了win10環(huán)境下配置python開發(fā)環(huán)境(vscode)的教程,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-10-10

