# -*- coding: utf-8 -*-
import re
import urllib
url=r'http://image.baidu.com/search/index?tn=baiduimage&ct=201326592&lm=-1&cl=2&ie=gbk&word=songzhongji'
#读取网页内容
imgcontent=urllib.urlopen(url).read()
flag_star='"objURL"'
flag_end='"fromURL"'
strdata='app.setData'
star_index= imgcontent.find(strdata)
end_index= imgcontent.find(strdata,imgcontent.find(strdata)+1)
strtxt=imgcontent[star_index:end_index]
list_star=[]
list_end=[]
pstar=strtxt.find(flag_star,0)
pend=strtxt.find(flag_end,0)
result_list=[]
while pstar!=-1 and pend!=1:
list_star.append(pstar)
list_end.append(pend)
pstar=strtxt.find(flag_star,pstar+1)
pend=strtxt.find(flag_end,pend+1)
if len(list_star)==len(list_end):
for i in range(len(list_star)):
result_list.append(strtxt[list_star[i]:list_end[i]].rstrip())
else:
print("有问题!")
fp=open('songzhongji.txt','w')
for line in result_list:
fp.write(line[10:-2])
fp.write("\n")
fp.close()
获取网页图片链接(http:/)
爬取图片链接
最新推荐文章于 2025-08-27 15:07:47 发布
本文介绍了一个简单的Python程序,用于从指定网页抓取包含宋仲基的图片链接,并将这些链接保存到本地文件中。该程序使用了urllib库来获取网页内容,并通过字符串操作解析所需的图片链接。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Stable-Diffusion-3.5
图片生成
Stable-Diffusion
Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

2308

被折叠的 条评论
为什么被折叠?



