|
@@ -6,8 +6,9 @@ import requests
|
|
|
class APILink():
|
|
|
#打开链接,返回title
|
|
|
def obtain_url_title(self,url):
|
|
|
- response = requests.get(url)
|
|
|
- response.encoding = 'utf-8' # 设置编码为gbk
|
|
|
+ response = requests.get(url,headers = {
|
|
|
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'})
|
|
|
+ response.encoding = 'utf-8' # 设置编码为utf-8
|
|
|
soup = BeautifulSoup(response.text, 'html.parser')
|
|
|
title = soup.title.string
|
|
|
return title
|