import requests
import re
def geturls():
# ********** Begin ********** #
url='http://www.qstheory.cn/dukan/qs/2014/2019-01/01/c_1123924172.htm'
headers={
'User-Agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36'
}
response=requests.get(url=url,headers=headers)
# print(response.encoding)
response = response.text
response = response.encode("ISO-8859-1")
response = response.decode("utf-8")
with open('./求是网.html','w',encoding='utf-8') as file:
file.write(response)
# <a href="http://www.qstheory.cn/dukan/hqwg/2019-01/10/c_1123970729.htm" target="_blank">本期重点推荐 </a>
ex = r'<a href="(.*?)" target="_blank">'
urls = re.findall(ex, response)
urls.pop(0)
urls.pop(0)
urls.pop(0)
urls.pop(-1)
urls.pop(-1)
# ********** End ********** #
return urls
if __name__ == "__main__":
urls = geturls()
for x in urls:
print(x)