Html 锚定标签有一半的链接,但当我点击链接时,它会打开一个包含完整链接的新页面

Html 锚定标签有一半的链接,但当我点击链接时,它会打开一个包含完整链接的新页面,html,python-3.x,beautifulsoup,href,Html,Python 3.x,Beautifulsoup,Href,澄清我的意思。这是html的外观: 我正在尝试使用此代码从突出显示的部分获取href链接 from bs4 import BeautifulSoup as soup from selenium import webdriver driver = webdriver.Chrome("chromedriver.exe") driver.get(r"http://wayback.archive.org/web/20101004060831/http://www.arcsoft.com:80/")

澄清我的意思。这是html的外观:

我正在尝试使用此代码从突出显示的部分获取href链接

from bs4 import BeautifulSoup as soup
from selenium import webdriver

driver = webdriver.Chrome("chromedriver.exe")
driver.get(r"http://wayback.archive.org/web/20101004060831/http://www.arcsoft.com:80/")

html = driver.page_source
page_soup = soup(html, "html.parser")

for i in page_soup.findAll("p", {"class": "impatient"}):
    print(i.a['href'])
代码返回
en us/index.asp
,根据程序,该值不正确。但是,当我在页面源中单击此href链接时,它会将我重定向到具有完整链接的网站

这是网站的最终URL:

是否有人可以帮助我获取此完整URL?

您可以等待错误消息页面,然后等待加载最终页面。错误页面有一个id为
error
的div。最后一个页面将始终有一个id为
siteWrapper
的div。您还可以使用TimeoutException处理没有错误页面的情况

从文件中:

如果 在该时间之后未找到任何内容,将抛出
TimeoutException
。通过 默认情况下,WebDriverWait每500次调用一次ExpectedCondition 毫秒,直到它成功返回。成功的返回值 对于ExpectedCondition,函数类型为布尔值true,或 非空对象

输出

http://web.archive.org/web/20100227101719/http://www.arcsoft.com/en-us/index.asp
现在
driver.page\u source
将获得最后一页的页面源代码

无需手动计算新url,然后转到该页面。

添加
a[“href”]
链接<代码>http://web.archive.org/web/20100227101719/http://www.arcsoft.com/ +a[“href”]
http://web.archive.org/web/20100227101719/http://www.arcsoft.com/en-us/index.asp