小钟弟弟教你引用url
作者:
1想得美 | 来源:发表于
2017-09-09 19:23 被阅读30次
这里的url指的是你爬取并保存到本地的url文本

url文本截图
#方法一
with open('02.txt', 'r', encoding='utf-8') as f:
f = f.read()
f=f.replace("\n", "") #去掉换行符
list = f.split('"') #以"为分隔符把f转化为列表
while '' in list: #删除列表中所有的空元素
list.remove('')
print(list)
#方法二
import re
with open('02.txt', 'r', encoding='utf-8') as f:
f = f.read()
pattern = re.compile('http.*?rd', re.S) # 这里url刚好全都以#rd结尾
a = re.findall(pattern, f)
print(a)
for b in a :
print(b)
本文标题:小钟弟弟教你引用url
本文链接:https://www.haomeiwen.com/subject/mkjajxtx.html
网友评论