* coding='utf-8' *
import sys,os,re
import requests
from bs4 import BeautifulSoup
------------------------
class fitgirl(objbect):
#headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
#'Referer':"https://www.manhuadb.com/author/370"
# }
#url='http://fitgirl-repacks.site/page/' #这样定义对不对
def __init__(self,page,html,url,headers,dict):
self.url='http://fitgirl-repacks.site/page/'
self.page=page
self.html=html
self.dict=dict{}
self.headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
#'Referer':"https://www.manhuadb.com/author/370"
}
def page_exx(self,html,page):
print("这是第{}内容".format(self.page))
soup=BeautifulSoup(self.html,'lxml')
for s in soup.find_all("article",id=re.compile("post-\d+$")):
dict["name"]=s.find('h1',class_="entry-title").getText()
dict["dizhi"]=s.find('a',href=re.compile('^magnet')).get('href')
print(dict.get("name")+"\n"+dict.get('dizhi'))
def main(self):
for p in range(1,100):
r = requests.get(self.url+str(p),self.headers)
try:
page_exx(r.text,p)
except:
pass
if name == "main":
fitgirl()
我运行错误,各位能帮我写一个对的类吗根据我这个 |