gpt4 book ai didi

python - 无法在需要时制定我的脚本供应方案

转载 作者:行者123 更新时间:2023-12-01 07:52:52 25 4
gpt4 key购买 nike

我用 python 创建了一个脚本来使用不同的域名,以便从中解析标题。我当前的尝试引发了以下明显的错误:

raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'Titanrestoration.Ca': No schema supplied. Perhaps you meant http://Titanrestoration.Ca?

到目前为止我的尝试:

import requests
from bs4 import BeautifulSoup

links = [
'Titanrestoration.Ca',
'Campbellroofing.Ca',
'Bjmillairebuilders.Ca',
'Rtroofing.Ca'
]

for link in links:
r = requests.get(link)
soup = BeautifulSoup(r.text,"lxml")
print(soup.title)

How can I make my script supply schemes if need be?

最佳答案

我们错过了这里的基本点。域名与协议(protocol)无关。无论 http 还是 https,域名都会重定向到实际站点。

import requests
from bs4 import BeautifulSoup

links = [
'Titanrestoration.Ca',
'Campbellroofing.Ca',
'Bjmillairebuilders.Ca',
'Rtroofing.Ca'
]

for link in links:
link = "http://" + link
r = requests.get(link)
soup = BeautifulSoup(r.text,"lxml")
print(soup.title)

如果您的架构已连接到某些域名,则应考虑剥离该架构并再次连接。

for link in links:
link = link.strip("http://")
link = "http://" + link
r = requests.get(link)
soup = BeautifulSoup(r.text,"lxml")
print(soup.title)

关于python - 无法在需要时制定我的脚本供应方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56107200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com