beautifulsoup 相关问题

Beautiful Soup是一个用于解析HTML / XML的Python包。此软件包的最新版本是版本4,导入为bs4。

Python 找不到模块(分别使用 bs4 和 selenium 进行尝试)

我已经反复安装和卸载了beautifulsoup4,但是无论我尝试做什么,当我尝试在shell中导入bs4时,我都会收到ModuleNotFoundError。 我使用的是 Windows 11 并使用 Python 3.10.7。 ...

回答 1 投票 0

使用 Python 抓取条形图上的向上缺口和向下缺口表格

我已经尝试了好几个小时来为条形图上的以下链接找到类或表 ID:Gap Up & Gap Down 我已经使用开发者工具检查了元素和源代码;还有我...

回答 1 投票 0

同一标签的多个值不被抓取

我的“房间数量”和“房间”搜索没有得到任何值。 https://www.zoopla.co.uk/property/uprn/906032139/ 我可以在这里看到我应该返回一些东西,但不应该返回...

回答 2 投票 0

无法找到 Youtube 观看次数

遵循有关抓取 YouTube 观看次数和视频日期的 YouTube 教程 [https://www.youtube.com/watch?v=Cc3mMH8XWC4] 我为每个视频制作了一个数据框,它有视图、clean_views、video_url、vide...

回答 1 投票 0

如何使用 bs4 在 python 中抓取单页应用程序网站

我正在通过 NBA 网站抓取球员姓名。玩家姓名网页是使用单页应用程序设计的。球员按字母顺序分布在多个页面上。我是

回答 1 投票 0

使用BeautifulSoup在Python中抓取照片URL

这段代码没有问题。我用它来抓取其他网站的照片网址,但是当我尝试抓取这个网站时,它没有得到任何信息,我试图找到实际的请求广告...

回答 1 投票 0

解析问题||尝试选择一个复选框而不是按下按钮并获取信息

我正在尝试制作一个发送随机电影的 Telegram 机器人(别介意,我现在正在控制台中的另一个文件中测试所有内容,稍后我将重构它),我很困惑。 我想...

回答 1 投票 0

使用 python beautifulsoup 抓取手机按钮

我想使用 beautifulsoup 从网站上抓取隐藏的电话号码 我提取了所有数据,除了电话号码没有出现

回答 1 投票 0

python、Edge,打开分屏并在右侧打开 pdf

如何使用Python在自动模式下使用Edge浏览器打开分屏? 我尝试用 google/chatgpt 搜索这个问题,但没有取得很大的成功。 看来这个新功能可能会在 2024 年 1 月推出 这可以用 ot 来完成吗...

回答 1 投票 0

美丽汤识别元素[重复]

我正在抓取丹佛市的财产税页面,并有一个包含地址的 csv。 URL 的格式为 https://www.denvergov.rg0/Property/?q=###%20DIR%20STREET%20SUFFIX%20。哪里...

回答 1 投票 0

在 BeautifulSoup 中将 < and > 解析为 <> 而不重新解析?

如何在这个例子中返回bold而不先美化汤? html_content = "这是粗体文本。" ...

回答 2 投票 0

Python 网页抓取错误“NoneType”对象没有属性“text”

所以,我尝试从 https://www.goodreads.com/list/show/83612.NY_Times_Fiction_Best_Sellers_2015 进行网络抓取。 这是我从 html 解析中得到的 html: 因此,我尝试从 https://www.goodreads.com/list/show/83612.NY_Times_Fiction_Best_Sellers_2015 进行网络抓取。 这是我从 html 解析得到的 html : <td valign="top" width="100%"> <a class="bookTitle" href="/book/show/18143977-all-the-light-we-cannot-see" itemprop="url"> <span aria-level="4" itemprop="name" role="heading">All the Light We Cannot See</span> </a> <br> <span class="by">by</span> <span itemprop="author" itemscope="" itemtype="http://schema.org/Person"> <div class="authorName__container"> <a class="authorName" href="https://www.goodreads.com/author/show/28186.Anthony_Doerr" itemprop="url"> <span itemprop="name">Anthony Doerr</span> </a> <span class="greyText">(Goodreads Author)</span> </div> </span> <br /> <div> <span class="greyText smallText uitext"> <span class="minirating"> <span class="stars staticStars notranslate"> <span class="staticStar p10" size="12x12"></span> <span class="staticStar p10" size="12x12"></span> <span class="staticStar p10" size="12x12"></span> <span class="staticStar p10" size="12x12"></span> <span class="staticStar p3" size="12x12"></span> </span> 4.32 avg rating — 1,622,659 ratings</span> </span> </div> <div style="margin-top: 5px"> <span class="smallText uitext"> <a href="#" onclick="Lightbox.showBoxByID('score_explanation', 300); return false;"> score: 12,706 </a>, <span class="greyText">and</span> <a href="#" id="loading_link_849498" onclick="new Ajax.Request('/list/list_book/4645304', {asynchronous:true, evalScripts:true, onFailure:function(request){Element.hide('loading_anim_849498');$('loading_link_849498').innerHTML = '&lt;span class=&quot;error&quot;&gt;ERROR&lt;/span&gt;try again';$('loading_link_849498').show();;Element.hide('loading_anim_849498');}, onLoading:function(request){;Element.show('loading_anim_849498');Element.hide('loading_link_849498')}, onSuccess:function(request){Element.hide('loading_anim_849498');Element.show('loading_link_849498');}, parameters:'authenticity_token=' + encodeURIComponent('6lhx6sV5qy11Lg1m0knlIiiBHvcno5EeLkBs5xzr5p9R3JgvjO2eYcBCjOVqr2bMfLnqe+8H9kU+pGpxJ4wsPw==')}); return false;"> 128 people voted </a> <img alt="Loading trans" class="loading" id="loading_anim_849498" src="https://s.gr-assets.com/assets/loading-trans-ced157046184c3bc7c180ffbfc6825a4.gif" style="display:none" />   </span> </div> </br> </td> 这是我用于网页抓取的代码 import bs4 from urllib.request import urlopen as uReq from bs4 import BeautifulSoup as soup myurl = "https://www.goodreads.com/list/show/83612.NY_Times_Fiction_Best_Sellers_2015" myurl uClient = uReq(myurl) page_html = uClient.read() uClient.close() page_soup = soup(page_html, "html.parser") tds = page_soup.findAll("td", {"width":"100%","valign":"top"}) for td in tds : juduls = td.a.select("span") judul = juduls[0].text print(judul) authors = td.div.select("a") author = authors[0].text print(author) rates = td.findAll("span", {"class":"greyText smallText uitext"}) rating = rates[0].text.strip().replace(",",".") print(rating) scores = td.findAll("div", {"style":"margin-top: 5px"}) score = scores[0].span.a.text.strip().replace("score: ","").replace(",",".") print(score) votes = td.findAll("div", {"style":"margin-top: 5px"}) vote = votes[0].find("a", {"id":"loading_link_849498"}).text.strip() print(vote) 结果: All the Light We Cannot See Anthony Doerr 4.32 avg rating — 1.622.659 ratings 12.706 128 people voted The Nightingale Kristin Hannah 4.62 avg rating — 1.307.242 ratings 10.824 --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) e:\project\webscrapping\scrap_for.py in line 38 36 print(score) 37 votes = td.findAll("div", {"style":"margin-top: 5px"}) ---> 38 vote = votes[0].find("a", {"id":"loading_link_849498"}).text.strip() 39 print(vote) AttributeError: 'NoneType' object has no attribute 'text' 我知道每本书的“id”:“loading_link_849498”都是不同的。我不知道如何获取具有不同 id 的标签中的文本。有什么解决办法吗? 之前谢谢你。 PS:我很抱歉我的英语不好,因为英语不是我的母语 我更喜欢 requests api 并对其进行了如下测试。 import requests from bs4 import BeautifulSoup # URL of the Goodreads list url = "https://www.goodreads.com/list/show/83612.NY_Times_Fiction_Best_Sellers_2015" # Fetch the page response = requests.get(url) page_content = response.text # Parse the HTML soup = BeautifulSoup(page_content, "html.parser") # Find all book entries. This might need adjustments based on actual page structure. books = soup.find_all("tr", itemtype="http://schema.org/Book") for book in books: # Extracting title, author, and rating title = book.find("a", class_="bookTitle").text.strip() author = book.find("a", class_="authorName").text.strip() rating = book.find("span", class_="minirating").text.strip() # Extracting score score_tag = book.find("a", onclick=lambda x: x and "Lightbox.showBoxByID('score_explanation'" in x) score = score_tag.text.split(': ')[1].replace(',', '') if score_tag else "N/A" # Extracting votes votes_tag = book.find("a", id=lambda x: x and x.startswith("loading_link_")) votes = votes_tag.text.split(' ')[0] if votes_tag else "N/A" # Print the extracted details print(f"Title: {title}") print(f"Author: {author}") print(f"Rating: {rating}") print(f"Score: {score}") print(f"Votes: {votes}") print("-" * 40)

回答 1 投票 0

使用 Python 从电子表格中导出值进行网络抓取

A。我的目标: 使用 Python 从 Excel 电子表格中提取唯一的 OCPO ID,并使用这些 ID 来网络抓取相应的公司名称和 NIN ID。 (注:NIN 和 OCPO ID 都是唯一的...

回答 1 投票 0

当页面源不包含我在浏览器上看到的内容时,网络抓取网站

假设我想抓取这个网站中的数据(马拉松跑步时间):https://www.valenciaciudaddelrunning.com/en/marathon/2021-marathon-ranking/ 当我右键单击并选择“

回答 2 投票 0

下载以.zip结尾的链接时出现问题

我正在尝试从网页批量下载一堆超链接压缩文件。我正在使用 Python 和 beautifulsoup。我在记事本中编写了代码并将其保存为 .py 。然后我运行了代码...

回答 1 投票 0

如何逆向BeautifulSoup.find_all()?

如何颠倒BeautifulSoup的find_all的顺序? (我想从末尾删除空的 p 标签,并在非空时停止。) soupcleanup = BeautifulSoup (contentsinputphp, 'html5lib') 对于元素...

回答 1 投票 0

BeautifulSoup4 中 find_all 的问题

我想在以下网站获取信息。我需要书名、代码、价格等。例如,让我们关注 ISBN 代码。我想在 html 中找到任何包含 ...

回答 1 投票 0

使用BeautifulSoup提取图像标题和图像url

我正在尝试使用 BeautifulSoup 从文章中提取图像 url 和图像标题。我可以将文章的图像 url 和图像标题与前面和后面的 HTML 分开,但我可以...

回答 4 投票 0

从 craigslist 搜索中抓取每张图片

我试图从 craigslist 搜索中提取每个图像 url,但似乎无法深入到 URL 本身。当我尝试 soup.find_all("a", { "class":"result-image gallery"} )[0].img 时,它不会返回...

回答 5 投票 0

加快多个网址上的网页抓取速度

我正在废弃大量 URL,以便在每个网页上仅获取一个特定数据。 问题是我的解决方案非常慢。 每页大约需要 9 秒,我想废弃大约 700 页...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.