簡體   English   中英

使用Selenium Webdriver(Python)從網站提取圖像

[英]Extract image from website using Selenium Webdriver (Python)

我需要抓取數千個子站點並提取信息。

現在,不幸的是,所討論的信息不是常規的HTML文本,而是動態呈現文本的圖像。

如何提取這些圖像以進一步處理它們? 我在Python上使用Selenium Webdriver。

mechanize加上BeautifulSoup幾乎是無法完成的。 圖像的進一步處理可以使用pytesser完成,但是我在那里沒有經驗。 有經驗的人提供有關Python OCR知識的建議會很有趣。

導入機械化,BeautifulSoup

browser = mechanize.Browser()
html = browser.open("http://www.dreamstime.com/free-photos")
soup = BeautifulSoup.BeautifulSoup(html)
for ii, image in enumerate(soup.findAll('img')):
    _src = image['src']
    if str(_src).startswith('http://') and str(_src).endswith('.jpg'):
        print 'Storing this image:', _src
        data = browser.open(_src).read()
        fl = 'image' + str(ii) + '.jpg'
        with open(fl, 'wb') as f:
            f.write(data)
        f.closed

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM