def _fetch_img_urls(self, keyword, safe_search=False):
# bing img search, https://gist.github.com/stephenhouser/c5e2b921c3770ed47eb3b75efbc94799
url = self._get_bing_url(keyword, safe_search=safe_search)
self.logger.debug('search url {}'.format(url))
header = {
'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/43.0.2357.134 Safari/537.36"}
soup = BeautifulSoup(urllib.request.urlopen(urllib.request.Request(url, headers=header)), 'html.parser')
imgs = [] # contains the link for Large original images, type of image
for a in soup.find_all("a", {"class": "iusc"}):
mad = json.loads(a["mad"])
turl = mad["turl"]
m = json.loads(a["m"])
murl = m["murl"]
image_name = urllib.parse.urlsplit(murl).path.split("/")[-1]
imgs.append((image_name, turl, murl))
return imgs
评论列表
文章目录