【发布时间】:2019-09-10 09:47:19
【问题描述】:
在我提供的那个视频中,这个人正在解析 Google 图片。
https://www.youtube.com/watch?v=MaWm1VpWj1A&list=LLiAY9i8Qha2Vx2j21Jk88PA&index=2&t=0s
import requests
from bs4 import BeautifulSoup as bs
import random
import json
import lxml.html
ua = "Mozilla / 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit / 537.36
(KHTML, как Gecko) Chrome / 58.0.3029.110 Safari / 537.36"
headers = {"User-Agent": random.choice(ua)}
r = requests.get("https://www.google.ru/search?tbm=isch&q=яблоко",
headers=headers)
html = r.content
soup = bs(html, "lxml")
images = soup.find_all("div", {"class": "rg_meta notranslate"})
images = [i.text for i in images]
images = [json.loads(i) for i in images]
print(images)
但我什么都没有
[]
进程以退出代码 0 结束
soup - 显示 html 文本,但 images = soup.find_all("div", {"class": "rg_meta notranslate"}) - 不显示任何内容
我已经查看了很多文章,我可以在任何地方找到一些东西并使用find_all 输出它 - 我什么也做不了,为什么,我不知道。
请帮助我了解发生了什么
【问题讨论】:
-
soup.find_all("img")有用吗?
标签: python-3.x beautifulsoup request