|
发表于 2022-7-1 19:50:54
|
显示全部楼层
你确定去了还是不行?我不信
错误发出来看看
随手试了哈,我是可以的哦
import requests
from bs4 import BeautifulSoup
response=requests.get('http://www.tianqihoubao.com/lishi/beijing/month/202005.html')
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:56.0) Gecko/20100101 Firefox/56.0'}
response=requests.get('http://www.tianqihoubao.com/lishi/beijing/month/202005.html',headers=headers)
#print(response.encoding)
#print(response)
soup=BeautifulSoup(response.text, features="lxml")
txt=soup.find('table', {'class':'b'})
tbody_val=txt.find_all('tr')
print(tbody_val)
==================================
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
======================== RESTART: E:\Users\desktop\1.py ========================
[<tr>
<td>
<b>日期</b></td>
<td>
<b>天气状况</b></td>
<td>
|
|