本文整理匯總了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