Python 3.x Beautifulsoup响应与视图源代码输出不匹配

Python 3.x Beautifulsoup响应与视图源代码输出不匹配,python-3.x,beautifulsoup,Python 3.x,Beautifulsoup,同时比较来自代码和chrome源代码的响应。我注意到从beautifulsoup返回的响应与页面源代码不匹配。我想获取class=“rc”,我可以在源代码页上看到带有“rc”的类,但在打印的响应中找不到它。我也检查了“lxml”和“html.parser” 我是python初学者,所以我的问题听起来可能很基本。此外,我已经查阅了一些与我的问题()相关的文章,但没有找到解决方案 下面是我的代码: import sys, requests import re import docx import w

同时比较来自代码和chrome源代码的响应。我注意到从beautifulsoup返回的响应与页面源代码不匹配。我想获取class=“rc”,我可以在源代码页上看到带有“rc”的类,但在打印的响应中找不到它。我也检查了“lxml”和“html.parser”

我是python初学者,所以我的问题听起来可能很基本。此外,我已经查阅了一些与我的问题()相关的文章,但没有找到解决方案

下面是我的代码:

import sys, requests
import re
import docx
import webbrowser
from bs4 import BeautifulSoup

query = sys.argv
url = "https://google.com/search?q=" + "+".join(query[1:])
print(url)
res = requests.get(url)
# print(res[:1000])

if res.status_code == 200:
    soup = BeautifulSoup(res.text, "html5lib")
    print(type(soup))
    all_select = soup.select("div", {"class": "rc"})
    print("All Select ", all_select)

我也遇到了同样的问题,尝试使用另一个解析器,比如“lxml”,而不是“html5lib”。

这个问题经常出现(一个月几次?)。例如,有些内容是动态的,其中包括一些类。有很多这样的例子可以帮助你做到这一点。