python网络数据学习范例-正则表达式+lambda函数

from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
html = urlopen("http://www.pythonscraping.com/pages/page3.html")
bsObj = BeautifulSoup(html,"html.parser")
images = bsObj.findAll("img",{"src":re.compile("\.\.\/img\/gifts\/img.*\.jpg")})#每个图片部分路径不同,用正则表达式代换
for image in images:
    print(image["src"])
这段代码会打印出图片的相对路径

lambda函数

定义了一个匿名函数,如g=lambda x:x+1      g(1)=2 




猜你喜欢

转载自blog.csdn.net/choven_meng/article/details/78164989
今日推荐