【问题标题】:How to scrape encoded with base 64 image and store in database using python如何使用 python 抓取使用 base 64 图像编码并存储在数据库中
【发布时间】:2019-11-12 18:05:40
【问题描述】:

我正在尝试 scrape 网站上的图像,但这些图像是用 base 64 编码的。那么我该如何使用 python、beautifulsoup 来做到这一点。

我尝试了使用 python urllib 的代码,但它不起作用。

import urllib
import urllib.request
from bs4 import BeautifulSoup
import base64
import os
from string import ascii_lowercase

def make_soup(url):
    thepage = urllib.request.urlopen(url)
    soupdata = BeautifulSoup(thepage, "html.parser")
    return soupdata
soup = make_soup("https://mahabhunakasha.mahabhumi.gov.in/bhunaksha/27/index.jsp")
soups = soup.decode('utf-8')

print(soups)
# for img in soup.findAll("src"):
#     print(img)

我想下载所有区域的所有图像并存储在 mongo 数据库中。

【问题讨论】:

  • 错误说明了什么?是SSLCertVerificationError吗?
  • @ ans2human :- 是的。 urllib.error.URLError:
  • 仅供参考,它是 scrape(和 scrapingscraperscraped)不是废品

标签: python html web-scraping beautifulsoup request


【解决方案1】:

为了避免我使用 selenium 的 SSL 错误,您可以下载一个 firefox exe 并传递可执行路径,然后您将能够在安装 selenium 模块后抓取页面:

#!pip install selenium

from bs4 import BeautifulSoup
from selenium import webdriver

driver = webdriver.Firefox(executable_path = 'C:\Gecko\geckodriver.exe')
thepage = driver.get("https://mahabhunakasha.mahabhumi.gov.in/bhunaksha/27/index.jsp")
html = driver.page_source
soup = BeautifulSoup(html,'lxml')

我在这个页面上没有看到任何图像,它似乎是一个画布类。

【讨论】:

  • 感谢您的回复。我直接通过猴子补丁绕过它ssl._create_default_https_context = ssl._create_unverified_context
猜你喜欢
  • 2016-02-18
  • 1970-01-01
  • 2018-08-20
  • 1970-01-01
  • 2019-02-16
  • 2019-02-16
  • 1970-01-01
  • 2018-09-01
  • 1970-01-01
相关资源
最近更新 更多