炎炎设计
如果您转到network Tab下方,XHR您将获得以下返回的链接keywords in json format。您不需要硒来获取关键字。https://www.naver.com/srchrank?frm=main&ag=all&gr=1&ma=-2&si=0&en=0&sp=0代码:import requestsurl='https://www.naver.com/srchrank?frm=main&ag=all&gr=1&ma=-2&si=0&en=0&sp=0'res=requests.get(url).json()print(res['data'])for item in res['data']: print(item['keyword'])在控制台上,第一次打印将返回 json 数据。[{'rank': 1, 'keyword': '챔피언', 'keyword_synonyms': []}, {'rank': 2, 'keyword': '확진자', 'keyword_synonyms': ['코로나 확진자', '추가 확진자', '2차 감염', '우한 폐렴 2차 감염', '6번째 확진자', '확진', '신종코로나', '5번째 확진자', '3번째 확진자', '국내 코로나 확진자', '코로나 바이러스 확진자', '한국 코로나 바이러스 확진자', '평택보건소', '한국 우한폐렴 확진자', '평택 우한폐렴', '우한 전세기', '코로나 확진', '세번째 확진자', '전세기', '국내 우한 폐렴 확진자', '신종코로나 확진자', '우한 폐렴 확진자']}, {'rank': 3, 'keyword': '박한희 변호사', 'keyword_synonyms': []}, {'rank': 4, 'keyword': '서가대', 'keyword_synonyms': []}, {'rank': 5, 'keyword': '박한희', 'keyword_synonyms': []}, {'rank': 6, 'keyword': '500만달러', 'keyword_synonyms': []}, {'rank': 7, 'keyword': '2020 서울가요대상', 'keyword_synonyms': []}, {'rank': 8, 'keyword': '신종코로나바이러스 확진자', 'keyword_synonyms': []}, {'rank': 9, 'keyword': '엄세범', 'keyword_synonyms': []}, {'rank': 10, 'keyword': '판빙빙', 'keyword_synonyms': []}, {'rank': 11, 'keyword': 'who 비상사태', 'keyword_synonyms': []}, {'rank': 12, 'keyword': '임오경', 'keyword_synonyms': []}, {'rank': 13, 'keyword': '수젠텍', 'keyword_synonyms': []}, {'rank': 14, 'keyword': '한해 clip clop', 'keyword_synonyms': []}, {'rank': 15, 'keyword': '장정윤 작가', 'keyword_synonyms': []}, {'rank': 16, 'keyword': '읍참마속', 'keyword_synonyms': []}, {'rank': 17, 'keyword': '재심', 'keyword_synonyms': ['영화 재심']}, {'rank': 18, 'keyword': '아이돌룸', 'keyword_synonyms': []}, {'rank': 19, 'keyword': '조윤선', 'keyword_synonyms': []}, {'rank': 20, 'keyword': '조원태', 'keyword_synonyms': []}]第二次打印将打印所有关键字。챔피언확진자박한희 변호사서가대박한희500만달러2020 서울가요대상신종코로나바이러스 확진자엄세범판빙빙who 비상사태임오경수젠텍한해 clip clop장정윤 작가읍참마속재심아이돌룸조윤선조원태
慕标5832272
有一个解决方案需要安装 pyppeteer 和 simple_scrapy。from simplified_scrapy.simplified_doc import SimplifiedDocfrom simplified_html.request_render import RequestRender# req = RequestRender({ 'executablePath': '/Applications/chrome.app/Contents/MacOS/Google Chrome'})req = RequestRender({ 'executablePath': 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'})def callback(html,url,extr): doc = SimplifiedDoc(html) keywords = doc.selects('span.ah_k') keywords = [each_line.text for each_line in keywords[:20]] print(keywords)req.get("https://www.naver.com/", callback,selectorOrFunctionOrTimeout='//span[@class="ah_k"]')结果:['포레스트', '장정윤 작가', '나홀로집에3', '박한희', '500만달러', '엄세범', '손승연', '군무원', 'who 비상사태', '소유진 부모님 나이차이', '맨유 맨시티', '진천', '한송네오텍', '진세연', '염동열', '임종석', '율희', '코미팜', '박한희 변호사', '김경란']分享编辑跟随