可以尝试使用requests库中的content属性来获取完整的HTML代码,例如:
import requests from bs4 import BeautifulSoup
url = 'https://example.com' r = requests.get(url) html = r.content soup = BeautifulSoup(html, 'html.parser')
这样就可以得到完整的HTML代码并用BeautifulSoup进行解析。注意,有些网站可能会使用JavaScript动态加载内容,这时需要使用selenium库来模拟浏览器行为获取完整的HTML代码。