通过结合使用scrapy在python中获取文本的基本URL?

时间:2017-09-12 07:02:21

标签: python scrapy

我试过这段代码:

src1 = "https://hms.harvard.edu/"<br/>
src = response.css('div.person-line > div > 
      img::attr("src")').extract_first()<br/>
src = sites/default/files/hms-faculty-emails/BX0UVXkP.jpg <br/>
import urlparse <br/>
urlparse.urljoin(src1, src)<br/>
https://hms.harvard.edu/sites/default/files/hms-faculty-emails/BX0UVXkP.jpg<br/>
src2 = urlparse.urljoin(src1,src)<br/>
email = pytesseract.image_to_string(Image.open(src2))<br/>

我收到此错误

ioerror errno 22 invalid mode ('rb') or filename

如何从文本图片中获取电子邮件文本..请帮忙吗?

1 个答案:

答案 0 :(得分:0)

您应该使用io.BufferIO缓冲区,因为您使用image_to_string路径调用函数http。您需要编写如下代码:

def get_text(src):
    response = urlopen(src)
    buffer = io.BytesIO(response.read())
    return pytesseract.image_to_string(Image.open(buffer))