欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

python中re正則匹配網(wǎng)頁中圖片url地址的示例分析-創(chuàng)新互聯(lián)

這篇文章主要為大家展示了“python中re正則匹配網(wǎng)頁中圖片url地址的示例分析”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“python中re正則匹配網(wǎng)頁中圖片url地址的示例分析”這篇文章吧。

站在用戶的角度思考問題,與客戶深入溝通,找到北關(guān)網(wǎng)站設(shè)計(jì)與北關(guān)網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名與空間、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋北關(guān)地區(qū)。

要抓取的圖片地址如圖所示:

python中re正則匹配網(wǎng)頁中圖片url地址的示例分析

首先,使用這個(gè)pattern

reg = re.compile('.*g_img={url: "(http.*?jpg)"')

無論怎么匹配都匹配不到,后來把網(wǎng)頁源碼抓下來放在notepad++中查看,并用notepad++的正則匹配查找,很輕易就匹配到了,如圖:

python中re正則匹配網(wǎng)頁中圖片url地址的示例分析

后來我寫了個(gè)測(cè)試代碼,把圖片地址在的那一行保存在一個(gè)字符串中,很快就匹配到了,如下面代碼所示,data是匹配不到的,然而line是可以匹配到的。

# -*-coding:utf-8-*-
import os
import re
 
f = open('bing.html','r')
 
line = r'''Bnp.Internal.Close(0,0,60056); } });;g_img={url: "https://az12410.vo.msecnd.net/homepage/app/2016hw/BingHalloween_BkgImg.jpg",id:'bgDiv',d:'200',cN'''
data = f.read().decode('utf-8','ignore').encode('gbk','ignore')
 
print " "
 
reg = re.compile('.*g_img={url: "(http.*?jpg)"')
 
if re.match(reg, data):
  m1 = reg.findall(data)
  print m1[0]
else:
  print("data Not match .")
  
print 20*'-'
#print line
if re.match(reg, line):
  m2 = reg.findall(line)
  print m2[0]
else:
  print("line Not match .")

由此可見line和data是有區(qū)別的,什么區(qū)別呢?那就是data是多行的,包含換行符,而line是單行的,沒有換行符。我有在字符串line中加了換行符,結(jié)果line沒有匹配到。

到這了原因就清楚了。原因就在這句話

re.compile('.*g_img={url: "(http.*?jpg)"')。

后來翻閱python文檔,發(fā)現(xiàn)re.compile()這個(gè)函數(shù)的第二個(gè)可選參數(shù)flags。這個(gè)參數(shù)是re中定義的常量,有如下常量

re.DEBUG Display debug information about compiled expression.
re.I 
re.IGNORECASE Perform case-insensitive matching; expressions like [A-Z] will match lowercase letters, too. This is not affected by the current locale.
re.L 


re.LOCALE Make \w, \W, \b, \B, \s and \S dependent on the current locale.
re.M 


re.MULTILINE When specified, the pattern character '^' matches at the beginning of the string and at the beginning of each line (immediately following each newline); and the pattern character '$' matches at the end of the string and at the end of each line (immediately preceding each newline). By default, '^' matches only at the beginning of the string, and '$' only at the end of the string and immediately before the newline (if any) at the end of the string.
re.S 


re.DOTALL Make the '.' special character match any character at all, including a newline; without this flag, '.' will match anything except a newline.re.U re.UNICODE Make \w, \W, \b, \B, \d, \D, \s and \S dependent on the Unicode character properties database.New in version 2.0.
re.X 


re.VERBOSE This flag allows you to write regular expressions that look nicer and are more readable by allowing you to visually separate logical sections of the pattern and add comments. Whitespace within the pattern is ignored, except when in a character class or when preceded by an unescaped backslash. When a line contains a # that is not in a character class and is not preceded by an unescaped backslash, all characters from the leftmost such # through the end of the line are ignored.

這里我們需要的就是re.S 讓'.'匹配所有字符,包括換行符。修改正則表達(dá)式為

reg = re.compile('.*g_img={url: "(http.*?jpg)"', re.S)

即可完美解決問題。

以上是“python中re正則匹配網(wǎng)頁中圖片url地址的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

新聞標(biāo)題:python中re正則匹配網(wǎng)頁中圖片url地址的示例分析-創(chuàng)新互聯(lián)
標(biāo)題網(wǎng)址:http://aaarwkj.com/article40/dpjheo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、網(wǎng)站內(nèi)鏈網(wǎng)站設(shè)計(jì)公司、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站制作全網(wǎng)營銷推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作
日本成熟亚洲中文字幕的| 中文字幕人妻丝袜一区一三区| 国产91香蕉在线精品| 天堂av日韩在线播放| 亚洲av资源一区二区| 91国产精品视频在线| 91日韩国产中文字幕| 国产91啦中文在线观看| 97精品少妇一区二区三区| 久久香蕉国产线看观看亚洲| 婷婷中文字幕在线视频| 亚洲视频在线男人天堂| 精品三级黄色国产片| 欧美精品日本一区二区| 一级片高清在线观看国产| 手机在线观看午夜小视频| 亚洲久久精品中文字幕| 国产三级黄在线观看| 亚洲成人精品青青香蕉| 亚洲综合国产一二三四五区| 欧美日韩亚洲综合国产人| 日韩欧美一区二区麻豆| 国产一区二区主播不卡| 欧美口爆吞精在线播放| 日韩在线中文字幕三区| av在线亚洲网站区一| 日韩成人中文字幕在线视频| 日本在线一区二区不卡视频| 日韩成人激情在线观看| 97免费观看在线观看| 免费国产午夜福利在线| 久久精品91久久久| 日本一区二区中文字幕在线 | 中文字幕av免费专区| 天天操夜夜操白天操晚上操| 少妇一区二区三区免费| 日韩有码中文字幕av | 一区二区五区日韩国产| 亚洲欧美一区二区中文字幕| 久久热福利视频就在这里| 美女被男人操国产精品|