简体   繁体   English

如何打印图像?

[英]How do I print the Images?

I want to print the images of the 30 nba teams drafting in the first round. 我想打印第一轮比赛中30支nba球队的图像。 However when I tell it to print it prints out the link instead of the image. 但是,当我告诉它进行打印时,它会打印出链接而不是图像。 How do I get it to print out the image instead of giving me the image link. 我如何获得它来打印图像而不是给我图像链接。 Here's my code: 这是我的代码:

import urllib2
from BeautifulSoup import BeautifulSoup
# or if your're using BeautifulSoup4:
# from bs4 import BeautifulSoup

soup = BeautifulSoup(urllib2.urlopen('http://www.cbssports.com/nba/draft/mock-draft').read())

rows = soup.findAll("table", attrs = {'class': 'data borderTop'})[0].tbody.findAll("tr")[2:]

for row in rows:
  fields = row.findAll("td")
  if len(fields) >= 3:
    anchor = row.findAll("td")[1].find("a")
    if anchor:
      print anchor

You need to convert the file into base64 encoding, this will give a string of data that can be moved around and stored if needed. 您需要将文件转换为base64编码,这将提供一串可以在需要时移动和存储的数据。 I normally do this with PHP so apologies if the Python is a little rough 我通常使用PHP来做到这一点,如果Python有点粗糙,我对此表示歉意

import urllib2
import base64
url = 'http://somesite.com/images/team_one.jpg'
grab = urllib2.urlopen(url)
encoded_image_string = base64.b64encode(grab.read())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM