怎么用python查找网站后台地址?
我用的是python3.x
import re
import time
import requests
class GetLinksTitles():
def links_titles(self):
links_titles = []
for i in range(211150, 211185):
url = "https://support.apple.com/zh-cn/HT" + str(i)
r = requests.get(url=url)
if r.status_code == 200:
html = r.content.decode('utf-8')
pattern = r'<title lang="zh-CN">(.*?) - Apple 支持</title>'
title = re.findall(pattern, html)
links_titles.append(url)
links_titles.append(title)
print("地址:%s 标题:%s"%(url, title))
else:
print("不存在:%d"%(i))
return links_titles
def save_links_titles(self, links_titles):
file = open('GetLinksTitles' + time.strftime('%Y%m%d%H%M%S') + '.txt', 'w')
for i in range(len(links_titles)):
text = str(links_titles[i]).replace("['", "").replace("']", "") + '\n'
file.write(text)
if __name__ == '__main__':
links_titles = GetLinksTitles().links_titles()
GetLinksTitles().save_links_titles(links_titles)
望采纳