アットウィキロゴ

cっこおい

import requests
 
def fresh(w):
 
 p1=w.rfind("<")
 p2=w.rfind(">",p1)
 sp=""
 if p1>-1:
    sp=w[p1:p2+1]
 
 k=w.replace(sp,"")
 return k
 
def clean_str(ww):
    for i in range(100):
        ww=fresh(ww)
    return ww
 
urlx="http://otokonomesuochi.blog.fc2.com/blog-entry-92.html"
 
r = requests.get(urlx)
m=r.text
 
a1="<div class=\"entry-content clearfix\">"
 
p1=m.find(a1)
p2=m.find("<div class=",p1+1)
 
stp=m[p1:p2]
 
x1=stp.split("</a>")
 
namex=[]
web=[]
for x2 in x1:
    p1=x2.find("http")
    p2=x2.find("html",p1+1)
    p3=x2.find(">",p2)
    x3=x2[p1:p2]
    su=x3+"html"
    sux=x2[p3+1:]
    web.append(su)
    namex.append(sux)
    print(su)
    print(sux)
 
for x2 in x1:
    p1=x2.find("http")
    p2=x2.find("html",p1+1)
    x3=x2[p1:p2]
    su=x3+"html"
    web.append(su)
 
for i in range(40):
    urlx=web[i]
    r = requests.get(urlx)
    m=r.text
 
    a1="<div class=\"entry-content clearfix\">"
 
    p1=m.find(a1)
    p2=m.find("<div class=",p1+1)
 
 
 
    stp=m[p1:p2]
 
    stp=stp.replace("<br />","△")
 
    stp=clean_str(stp)
 
    x=stp.split("△")
 
    print(namex[i])
    f=open("data/"+namex[i]+".txt","w",encoding="utf-8")
    for x1 in x:
        f.write(x1+"\n")
    f.close()
 
最終更新:2018年02月10日 23:58