import requests ####指定url url = 'http://www.mee.gov.cn/' ####发起请求 response = requests.get(url) ####获取相应信息 page_text=response print(page_text) ####持久化存储 with open('./www.mee.gov.html','w',encoding='utf-8') as fp: fp.write((page_text.text) print('爬取结束!!!') File "/var/folders/wj/mvzl124x2xv1ywq89bjh3qkm0000gn/T/ipykernel_71039/684186021.py", line 12 print('爬取结束!!!') ^ SyntaxError: invalid syntax
时间: 2024-03-29 19:40:07 浏览: 104
1_import requests #导入请求包.ini
你的代码缺少括号,导致在 `fp.write((page_text.text)` 这一行处出现了语法错误。你需要在这一行代码中添加一个缺少的右括号,修改为 `fp.write(page_text.text)`。同时,在 `print('爬取结束!!!')` 这一行代码后也缺少了一个右括号,需要添加上去。修改后的代码如下:
```python
import requests
####指定url
url = 'http://www.mee.gov.cn/'
####发起请求
response = requests.get(url)
####获取相应信息
page_text = response
print(page_text)
####持久化存储
with open('./www.mee.gov.html','w',encoding='utf-8') as fp:
fp.write(page_text.text)
print('爬取结束!!!')
```
阅读全文