简单python爬虫

来源:互联网 发布:wbs 协作软件 编辑:程序博客网 时间:2024/04/27 18:51
import osimport urllibimport urllib.request as requestfrom bs4 import BeautifulSoupdef catch(url):    f = open('filename.txt','w')    response = request.urlopen(url)    html = response.read()    soup = BeautifulSoup(html)    for list in soup.find_all('h3'):        if list.string:            f.writelines(list.string)        else:            f.write('\n')    f.close()if __name__ == '__main__':    print("""----------------loading code...----------------    """)url = '爬取的网址'catch(url)

用于爬取指定网页的python3语法爬虫,并且将制定爬取的信息保存到指定的文件夹的txt文件下,这是第一个爬虫程序,参考了博友的博客代码,高效简洁,可作为入门小程序

0 0
原创粉丝点击