本文整理汇总了Python中Picture.timage方法的典型用法代码示例。如果您正苦于以下问题:Python Picture.timage方法的具体用法?Python Picture.timage怎么用?Python Picture.timage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Picture
的用法示例。
在下文中一共展示了Picture.timage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BeautifulSoup
# 需要导入模块: import Picture [as 别名]
# 或者: from Picture import timage [as 别名]
#print html
soup = BeautifulSoup(str(html),'html.parser',from_encoding='utf-8')
#print soup
From = soup.title.get_text()
Div = soup.find_all('div',class_='carousel-caption')
#清空原来数据
sql="TRUNCATE `dj_bbs_news;"
Mysql.MysqlHelper().In_sql(sql)
x = 1
for line in Div:
soup2 = BeautifulSoup(str(line),'html.parser',from_encoding='utf-8')
Url = soup2.find('a')['href']
html2 = getHtml(soup2.find('a')['href'])
Tltle = BeautifulSoup(html2,'html.parser',from_encoding='utf-8').find('h1',class_='ph').get_text()
Img = soup.find('img',alt='%s' % Tltle.strip())['src']
#print Img
try:
sql='''INSERT INTO `dj_bbs_news`(title,summary,url,favor_count,reply_count,create_date,image_urls) VALUES("%s",'%s','%s','0','0',NOW(),'news/%s.jpg');''' %(Tltle,From,Url,x)
#print sql
Mysql.MysqlHelper().In_sql(sql)
except Exception,e:
print e
local = os.path.join('D:/test/bbs/static/news/','%s.jpg' % x)
urllib.urlretrieve(Img,local)
#处理图片
Picture.timage("D:/test/bbs/static/news/%s.jpg" % x, 'D:/test/bbs/static/news/')
print '已处理完%s.jpg'% x
x+=1