马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 小甲鱼的铁粉 于 2021-2-4 10:15 编辑
想提取出来网页的评论区的整个div,但是就算是find_all("div"),没有加任何信息,也找不到任何div,soup输出的内容正常,就是执行过divs = soup.find_all('div')就不对了,麻烦鱼油们帮我看一下import re
import os
import requests
from bs4 import BeautifulSoup
def get_div():
url = "https://www.mgtv.com/b/350683/11017269.html?fpa=76&fpos=3&lastp=ch_home"
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0"}
response = requests.get(url, headers = headers)
soup = BeautifulSoup(response.text, 'lxml')
#print(soup)
divs = soup.find_all('div')
print(divs)
if __name__ == "__main__":
get_div()
输出
<div data-server-rendered="true" id="__nuxt"><!-- --><div id="__layout"><div><noscript>
请启用 JavaScript
</noscript> <!-- --> <!-- --> <div class="m-video-error-infomessage" style="display:none;"><div class="video-error-infomessage"><h4>您将了解到本次错误原因:</h4><p>错误码:<em></em></p><p>错误详情:<em></em></p><p class="video-error-infomessage-closed"><a href="javascript:;">关闭</a></p></div></div> <!-- --></div></div></div>
|