import requests
import bs4
resp=requests.get('https://www.baidu.com') #请求百度首页
print(resp) #打印请求结果的状态码
print(resp.content) #打印请求到的网页源码
bsobj= bs4.BeautifulSoup(resp.content, 'lxml')
a_list=bsobj.find_all('a')
text=''
for a in a_list:
href=(a.get('href'))
text+=href+'\n'
with open('url.txt','w') as f:
f.write(text)
python爬虫
于 2022-01-25 16:56:02 首次发布