Python复制或打印超链接

Python复制或打印超链接,python,hyperlink,copy,urllib2,Python,Hyperlink,Copy,Urllib2,嘿,我想从word复制或打印超链接 例如: 使用哪种代码可以实现这一点 我可以使用urllib2吗 如果有人会说德语,那会更简单:)您需要使用: 当然,这是非常基本的代码。如果您查看该模块的文档,您将看到许多其他方法可用于实现您的结果:)您是否从网站上获取单词?是的,使用:htmlfile=urllib2.urlopen('link')htmltext=htmlfile.read()什么是['href']在最后一行?@user2534685好的,那么你知道a标记中有类似于?。'href'所做的是

嘿,我想从word复制或打印超链接

例如:

使用哪种代码可以实现这一点

我可以使用urllib2吗

如果有人会说德语,那会更简单:)

您需要使用:


当然,这是非常基本的代码。如果您查看该模块的文档,您将看到许多其他方法可用于实现您的结果:)

您是否从网站上获取单词?是的,使用:htmlfile=urllib2.urlopen('link')htmltext=htmlfile.read()什么是['href']在最后一行?@user2534685好的,那么你知道a标记中有类似于
?。
'href'
所做的是访问
http://hyperlink.com
在很多网页的源代码中也是一个超链接。例如:href='/b/ref=topnav\u giftcert?ie=UTF8&node=3063530011'class='nav\u a'>礼品卡@user2534685是的,可能有很多。您可以使用
find_all()
,它可以查找页面上的所有a标记,但我仅使用代码find_all()获取示例:/gp/prime/signup/videos。超链接是:
from bs4 import BeautifulSoup
htmlfile = urllib2.urlopen(url).read()
soup = BeautifulSoup(htmlfile)
a_tag = soup.find('a') # This finds the first occurrence of an a tag.
print a_tag['href'] # Prints the link which the a_tag links to. (hyperlink)