当前位置: 首页>>代码示例>>Python>>正文


Python Picture.timage方法代码示例

本文整理汇总了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

开发者ID:weihxa,项目名称:bbs,代码行数:31,代码来源:demo.py


注:本文中的Picture.timage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。