Python 脚本转到 link

Python script to go to a link

大家早上好,

我想创建一个可以找到 link 并自动点击它的脚本,例如通过找到 link 的文本。

你能帮帮我吗?

谢谢:)

my example

你可以试试这个。它将找到所有 link 并在页面上打印 link 和所有 link 的标题。

import requests
from bs4 import BeautifulSoup
soup = BeautifulSoup(requests.get('https://example.com/').content, 'lxml').find_all('a', href=True)
[print(x.text, x['href']) for x in soup]

如果你想找到一个特定的 link,那么你必须找到一个 id 或类似包装 div 或其他标签的东西:)