使用 python 抓取网站 - BeautifulSoup

阿肯曼迪拉

这是我在这里的第一个问题,我开始学习 python,已经看了很多视频。

感谢您能在我下面的代码中启发我,

我收到以下错误“AttributeError: 'NoneType' 对象没有属性 'find'”

我只需要搜索一个词(在这个例子中是鹦鹉)并在类中刮下并列出标题:“片段”

import requests
from bs4 import BeautifulSoup

page = requests.get("http://web.archive.org/web/*/parrot#")
soup = BeautifulSoup(page.content, 'html.parser')
container = soup.find("div", {"class":"search-result-container container"})
mysnippet = container.find("div", {"class":"snippet"})
print("List of Titles")
print(mysnippet)
巴维亚·帕里克
  1. 如果你打印你的汤,你会发现数据不存在,甚至那个 div 标签包含 ::before 意味着动态加载

  2. 所以你可以先尝试这种方法,先进入 chrome 开发者模式,然后网络选项卡现在刷新你的浏览器

  3. 在 xhr 中,您可以在 Name 选项卡下找到链接,其中第二个链接包含 json 数据,因此您可以通过从该查找标题中复制链接地址来获取该链接

 import requests
 res=requests.get("http://web.archive.org/__wb/search/anchor?q=parrot")
 main_data=res.json()
 for i in range(len(main_data)):
     print(main_data[i]['text'])

输出:

parrot
dead parrot society
parrot forum
parrot vids
....

图片:

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用python中的BeautifulSoup从网站抓取报告

使用python 2.7和beautifulsoup 4进行网站抓取

python-使用BeautifulSoup抓取ajax网站的Web

使用python和beautifulsoup抓取多页网站

使用BeautifulSoup抓取特定网站

Python beautifulsoup,抓取网站中的表格

无法使用beautifulsoup抓取日本网站

使用BeautifulSoup抓取网站时显示符号

使用BeautifulSoup网站抓取IMDb页面

无法使用BeautifulSoup4抓取网站

使用BeautifulSoup抓取网站时阅读页码

使用BeautifulSoup抓取网站后缺少文本

使用BeautifulSoup 4.8.2从网站抓取表格

使用 BeautifulSoup 从网站抓取数据的问题

不使用beautifulsoup抓取网站数据

抓取“ __hpKey”的网站,然后在python中使用请求和beautifulsoup登录

如何抓取一个需要使用python和beautifulsoup登录的网站?

使用来自 AJAX 网站的 selenium 和 beautifulsoup 在 python 中抓取图像

使用 Python 中的 BeautifulSoup 从新闻网站主页上抓取标题

如何使用python和beautifulsoup4循环抓取网站中多个页面的数据

如何使用python中的BeautifulSoup库从具有“查看更多”选项的网站上抓取数据

在python 3.6中使用beautifulsoup4抓取网站以获取产品信息时

如何使用BeautifulSoup从python网站中未加载的选项卡中抓取表格数据

无法使用python抓取网站

使用BeautifulSoup Python抓取网页

带有过滤器的Python BeautifulSoup抓取网站

BeautifulSoup Python Selenium - 在抓取网站之前等待推文加载

使用Python / BeautifulSoup进行Web抓取:具有指向个人资料的多个链接的网站>需要个人资料内容

使用beautifulsoup抓取HTML网站ID的特定部分