【发布时间】:2019-07-05 19:00:42
【问题描述】:
我正在尝试从 this site 中删除类 div id="ideas_body",但它似乎丢失了。我已经尝试过链接到这篇文章(Missing parts on Beautiful Soup results)的different parsers,但没有一个成功。
这是我的代码:
import requests
from bs4 import BeautifulSoup
import lxml
# Set Soup
url = 'https://www.com/ideas#'
headers = {'User-Agent': 'Mozilla/5.0'}
page = requests.get(url, headers=headers)
以及我尝试过的不成功的解析器:
soup = BeautifulSoup(page.content, 'lxml-xml')soup = BeautifulSoup(page.content, 'html.parser')soup = BeautifulSoup(page.content, 'html.parser-xml')soup = BeautifulSoup(page.content, 'html5lib')
那么我怎样才能解析这个 ID 以便抓取它呢?
【问题讨论】:
-
我在 HTML 中看不到
class="ideas_body"。我看到id="ideas_body"。 -
@Barmar - 抱歉错字。刚刚修复
-
可能这个页面使用了JavaScript来添加这个元素,然后
BeautifulSoup就没有用了,因为它不能运行JavaScript。 -
不抓取网页,调用网页填写DIV的API。
-
抓取网页的通常原因是没有等效的 API。但显然有这种情况。
标签: python xml web-scraping beautifulsoup