python学习第一天

今天简单学习了一些python

做了第一个简单的案例

 

 

import re
import urllib.request
import csv

url = "https://blog.csdn.net/u014636245/article/details/91426736"
header={"User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 "
                     "like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) "
                     "Version/13.0.3 Mobile/15E148 Safari/604.1 Edg/101.0.4951.54"}

urr = urllib.request.Request(url,headers=header)

# content = urllib.request.urlopen(urr).read().decode()
content = urllib.request.urlopen(urr).read().decode()

str=r"<a.*?href=.*?pdf.*?<\/a>"
urls = re.findall(str, content)

fileName=open('C:/Users/97807/Desktop/Data.csv','wt',newline='',encoding='utf_8_sig')
for u in urls:
    str=r'http.*?pdf'
    u = re.findall(str, u)
    print(u)



#
# res=r'<a .*?>(.*?)</a>'
# texts = re.findall(res, content, re.S | re.M)
# for t in texts:
#     print(t)

  python的语法还真是,,,奇奇怪怪的哈哈,

posted on 2022-05-31 07:57  付治齐吖  阅读(21)  评论(0)    收藏  举报