Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在不同的html标记中使用内容值抓取网页_Python_Html_Web Scraping_Beautifulsoup - Fatal编程技术网

Python 在不同的html标记中使用内容值抓取网页

Python 在不同的html标记中使用内容值抓取网页,python,html,web-scraping,beautifulsoup,Python,Html,Web Scraping,Beautifulsoup,我是新的刮和编码以及。到目前为止,我能够使用以下代码使用beautiful soup刮取数据: sub_soup = BeautifulSoup(sub_page, 'html.parser') content = sub_soup.find('div',class_='detail-view-content') print(content) 如果标记和类的格式为: <div class="masthead-card masthead-hover"> 但当

我是新的刮和编码以及。到目前为止,我能够使用以下代码使用beautiful soup刮取数据:

sub_soup = BeautifulSoup(sub_page, 'html.parser')
content = sub_soup.find('div',class_='detail-view-content')
print(content)
如果标记和类的格式为:

<div class="masthead-card masthead-hover">

但当格式与内容匹配时失败:

<span _ngcontent-ixr-c5="" class="btn-trailer-text">
or
<div _ngcontent-wak-c4="" class="col-md-6">
下面是我试图抓取的内容网页截图示例:


所有我尝试过的结果都是空白或“无”。我遗漏了什么。

您是如何访问该页面的?这个内容很可能是动态注入JS的。您可能必须手动点击API或使用Web驱动程序。@ggorlen我正在使用他们的site.xml并从中获取url。此后使用BS4将其废弃。@ggorlen您是对的,html标记在每次刷新时都会更改。这是另一个问题。这能解决您的问题吗:html还是.xml?我想你指的是html。尝试
soup。选择一个(“.detail view title”).split(“|”)[-1].strip()
这也有助于查看这两种类型的html示例(包括要提取的文本)