编程知识 cdmana.com

Wrote a program, running problems, do not know how to solve

1、 Learning crawler , Follow the video

img

#-- coding:utf-8--

if name == 'main':
url='https://www.sogou.com/web?query=%E4%BD%A0%E7%9A%84%E5%90%8D%E5%AD%97%27

header = {    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36'}kw = input('enter a word:')param={    'query':kw}response = requests.get(url=url,params=param,headers=header)page_text=response.textfileName = kw+'.html'with open(fileName,'w',encoding='utf-8') as fp:    fp.write(page_text)print(fileName,' Saved successfully !!!')

2、

img




Take the answer :

Code

# -*- coding = utf-8 -*-# @time:2022/5/7 21:46# Author:TL.mr# @File:test01.py# @Software:PyCharmimport requestsif __name__ == '__main__':    url='https://www.sogou.com/web?query=%E4%BD%A0%E7%9A%84%E5%90%8D%E5%AD%97%27'    header = {        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36'    }    kw = input('enter a word:')    param={        'query':kw    }    response = requests.get(url=url,params=param,headers=header)    page_text=response.text    fileName = kw+'.html'    with open(fileName,'w',encoding='utf-8') as fp:        fp.write(page_text)    print(fileName,' Saved successfully !!!')

effect :

img

img


Hope to adopt , thank you


版权声明
本文为[CSDN Q & A]所创,转载请带上原文链接,感谢
https://cdmana.com/2022/134/202205072139434974.html

Scroll to Top