大佬教程收集整理的这篇文章主要介绍了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,请注明来意。