import requests
from bs4 import BeautifulSoup
result=requests.get('http://textfiles.com/stories/').text
soup=BeautifulSoup (result, 'lxml')
stories=soup.find_all('tr')
print (stories)
該find方法有效,但find_all我不確定為什么可能是因為它沒有類?
uj5u.com熱心網友回復:
正確的代碼是
import requests
from bs4 import BeautifulSoup
result=requests.get('http://textfiles.com/stories/')
soup = BeautifulSoup(result.content, 'html5lib')
stories=soup.find_all('tr')
您可以通過以下方式訪問每個“tr”
stories[0]
0 可以替換為串列中的任何數字您也可以使用 Pandas,例如
import pandas
import requests
from bs4 import BeautifulSoup
result=requests.get('http://textfiles.com/stories/')
soup = BeautifulSoup(result.content, 'html5lib')
df=pandas.read_html(soup.prettify())
print(df)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/460070.html
上一篇:我想找到一個不同的標簽beautifulsouppython函式
下一篇:如何知道選擇和查找之間的區別
