[Python] 纯文本查看 复制代码 import requests
from lxml import etree
import threading
ls = []
thread_ls = []
def thread(func):
def main(*args,**kwargs):
thread_ls.append(threading.Thread(target=func,args=args,kwargs=kwargs))
thread_ls[-1].start()
return main
@thread
def 爬取内容(page):
url = f"http://fund.eastmoney.com/a/cjjgd_{page}.html"
r =requests.get(url)
ls.extend(etree.HTML(r.text).xpath(r'//div[@class="infos"]/ul/li/a/@title'))
if __name__ == '__main__':
for i in range(1,11+1):
爬取内容(i)
for i in thread_ls:
i.join()
采集的所有内容 = "\n".join(ls)
print(采集的所有内容)
|