到底哪里出了错,没反应
import requestsimport re
import json
import os
session = requests.session()
def fetch_url(url):
return session.get(url).content.decode('gbk')
def get_doc_id(url):
return re.findall('view/(.*).html', url)
def parse_type(content):
return re.findall(r"docType.*?:.*?\'(.*?)\',", content)
def parse_title(content):
return re.findall(r"title.*?\'(.*?)\',", content)
def parse_doc(content):
result = ''
url_list = re.findall('(https.*?0.json.*?)\\\\\x22}', content)
url_list =
for url in url_list[:-5]:
content = fetch_url(url)
y = 0
txtlists = re.findall('"c":"(.*?)".*?"y":(.*?),', content)
for item in txtlists:
if not y == item:
y = item
n = '\n'
else:
n = ''
result += n
result += item.encode('utf-8').decode('unicode_escape', 'ignore')
return result
def parse_txt(doc_id):
content_url = 'https://wenku.baidu.com/api/doc/getdocinfo?callback=cb&doc_id=' + doc_id
content = fetch_url(content_url)
md5 = re.findall('"md5sum":"(.*?)"', content)
dummy_pn = re.findall('"totalPageNum":"(.*?)"', content)
rsign = re.findall("\"rsign\":\"(.*?)\"", content)
content_url = 'https://wkretype.bdimg.com/retype/text/' + \
doc_id + '?rn=' + 'pn' + '&type=txt' + md5 + '&rsign=' + rsign
result = ''
for item in content:
for i in item['parags']:
result += i["c"].replace('\\r', '\r').replace('\\n', '\n')
return result
def parse_other(doc_id):
content_url = "https://wenku.baidu.com/browse/getbcsurl?doc_id=" + \
doc_id + "&pn=1&rn=99999&type=ppt"
content = fetch_url(content_url)
url_list = re.findall(content, '{"zoom":"(.*?)","page"')
url_list =
if not os.path.exists(doc_id):
os.mkdir(doc_id)
for index, url in enumerate(url_list):
content = session.get(url).content
path: str = os.path.join(doc_id, str(index) + '.jpg')
with open(path, 'wb') as f:
f.write(content)
print("文件保存在" + doc_id + "文件夹")
你只是谢了函数没有执行怎么会有反应?应该是学习别人代码复制下来的吧?也不知道你到底想要什么目的
调用了函数就会有反应了 在最后加一个if __name__ == "__main__":
# 你要运行的函数
页:
[1]