import requests
from bs4 import BeautifulSoup
####url,titleurl,headers 已修改为Google网站。
url = ‘https://mail.google.com/mail/’
titleurl = ‘www.google.com’
headers = {
‘Host’: ‘www.google.com’,
‘Referer’: ‘https://mail.google.com/mail/u/0/’,
‘User-Agent’: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36}
res = requests.get(url,headers = headers)
res.encoding = ‘utf-8’
html=res.text
soup = BeautifulSoup(html,“html.parser”)
##########查找a标签,
for a in soup.find_all(‘a’, href=True):
if a.get_text(strip=True):
####### 获取href中的值
m=a[‘href’]
#获取a标签的值
l=a.string
n=titleurl
####### 拼接titleurl和href
print(l,n+m)
python 获取a标签值以及href值,爬取下载地址
最新推荐文章于 2022-11-24 20:29:46 发布