程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了BeautifulSoup 断链检查器/网络爬虫大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决BeautifulSoup 断链检查器/网络爬虫?

开发过程中遇到BeautifulSoup 断链检查器/网络爬虫的问题如何解决?下面主要结合日常开发的经验,给出你关于BeautifulSoup 断链检查器/网络爬虫的解决方法建议,希望对你解决BeautifulSoup 断链检查器/网络爬虫有所启发或帮助;

我正在尝试基于此操作方法构建一个断开的链接检查器:https://dev.to/arvindmehairjan/build-a-web-crawler-to-check-for-broken-links-with-python-beautifulsoup-39mg

但是,我在代码行上遇到了问题,因为当我运行程序时,我收到此错误消息:file "/Users/documents/brokenlinkchecker.py",line 26 print(f"Url: { link.get('href')} " + f"| 状态码:{response_codE}") 语法错误:语法无效

我一直在思可能导致此语法错误的原因。有没有人对我可以做些什么来使这个程序起作用有什么建议?

非常感谢!

代码如下:

# import librarIEs
from bs4 import BeautifulSoup,SoupSTrainer
import requests

# Prompt user to enter the URL
url = input("Enter your url: ")

# Make a request to get the URL
page = requests.get(url)

# Get the response code of given URL
response_code = str(page.status_code)

# display the text of the URL in str
data = page.text

# Use BeautifulSoup to use the built-in methods
soup = BeautifulSoup(data)

# Iterate over all links on the given URL with the response code next to it
for link in soup.find_all('a'):
    print(f"Url: {link.get('href')} " + f"| Status Code: {response_codE}")

解决方法

您必须将附加参数 features="lxml"features="html.parser" 传递给 BeautifulSoup 构造函数。

soup = BeautifulSoup(data,features="html.parser")

大佬总结

以上是大佬教程为你收集整理的BeautifulSoup 断链检查器/网络爬虫全部内容,希望文章能够帮你解决BeautifulSoup 断链检查器/网络爬虫所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:BeautifulSoup