【发布时间】:2020-12-31 03:10:00
【问题描述】:
我正在做一个需要我查看网页的项目,但要进一步使用 HTML,我必须完整地查看它,而不是把一堆线条和图片混合在一起。有没有办法使用 BeautifulSoup 解析 CSS 和 HTML?
这是我的代码:
from bs4 import BeautifulSoup
def get_html(url, name):
r = requests.get(url)
r.encoding = 'utf8'
return r.text
link = 'https://www.labirint.ru/books/255282/'
with open('labirint.html', 'w', encoding='utf-8') as file:
file.write(get_html(link, '255282'))
警告:页面:https://www.labirint.ru/books/255282/ 重定向到 https://www.labirint.ru/books/733371/。
【问题讨论】:
标签: python html python-3.x web-scraping beautifulsoup