【问题标题】:Unable to open LOCAL HTML page for scrapping using BS$ Python无法打开本地 HTML 页面以使用 BS$ Python 进行抓取
【发布时间】:2023-01-04 06:11:16
【问题描述】:

我编写了以下代码来打开保存在桌面上的本地 HTML 文件:

但是,在运行此代码时出现以下错误:

我以前没有用 Python 或 BS4 处理这个的经验。网上试了各种解决办法都解决不了。

代码:

import csv
from email import header
from fileinput import filename
from tokenize import Name
import requests
from bs4 import BeautifulSoup


url = "C:\  Users\  ASUS\   Desktop\    payment.html"
page=open(url)
# r=requests.get(url)
# htmlContent = r.content
soup = BeautifulSoup(page.read())



head_tag = soup.head
for child in head_tag.descendants:
    print(child)

需要帮忙!

先感谢您。

【问题讨论】:

    标签: python beautifulsoup html-parsing offline


    【解决方案1】:

    它的 unicode 错误在路径前加上 r(以生成原始字符串):

    url = r"C:  Users  ASUS   Desktop    payment.html"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-30
      • 1970-01-01
      • 1970-01-01
      • 2013-03-17
      • 2018-12-03
      • 1970-01-01
      • 2021-10-19
      • 2020-11-15
      相关资源
      最近更新 更多