import aiohttp import asyncio from fake_useragent import UserAgent from pyquery import PyQuery as pq import time ua = UserAgent(verify_ssl=False, path='D:/Pycharm/fake_useragent.json') lists = [] start = time.time() def ua_random(): headers = { 'use_agent' : ua.random } return headers async def scrape_text(url): async with aiohttp.ClientSession(headers=ua_random()) as session: async with session.get(url) as response: result = await response.text() await session.close() return result async def scrap_url(html): doc = pq(html) links = doc('.clearfix li a') for link in links.items(): lists.append('https://pic.netbian.com' + link.attr('href')) async def scrap_index(page): url = f'https://pic.netbian.com/4kmeinv/index_{page}.html' html = await scrape_text(url) await scrap_url(html) async def main(): scrap_index_tasks = [asyncio.ensure_future(scrap_index(page)) for page in range(2, 10)] await asyncio.gather(*scrap_index_tasks) print(lists) if name == 'main': loop = asyncio.get_event_loop() loop.run_until_complete(main()) print('总用时:', time.time()-start)出现了init() got an unexpected keyword argument 'path'错误
时间: 2024-04-27 15:25:21 浏览: 208
json fake_useragent fake_useragent
这个错误通常表示在创建UserAgent对象时,使用了一个不支持的参数。从错误信息看,可能是fake_useragent库的UserAgent类不支持传入path参数。
请检查你在创建UserAgent对象时传入的参数,特别是参数名称是否正确拼写。如果你确定参数名称正确,那么可能是fake_useragent库的版本不支持该参数,需要升级到最新版本。如果你需要更具体的帮助,请提供更多的上下文和代码。
阅读全文