我知道我想做的是最簡單的,但它讓我大吃一驚。我想使用 BeautifulSoup從 HTML 頁面 ( https://partner.microsoft.com/en-us/membership/application-development-competency ) 中提取資料。為此,我想我需要使用 .find() 函式。不知道該怎么辦了。感謝每一種形式的幫助。這是我正在使用的 HTML:[在此處輸入影像描述][1] [1]:https://i.stack.imgur.com/sHAMF.png
import requests
from bs4 import BeautifulSoup
url = 'https://partner.microsoft.com/en-us/membership/application-development-competency'
res = requests.get(url)
html_page = res.content
soup = BeautifulSoup(html_page, 'html.parser')
text = soup.find("div",{"class":"col-md4[2]"})
output = ''
blacklist = [
'style',
'head',
'meta',
'col-md4[0]',
'col-md4[1]',
]
for t in text:
if t.parent.name not in blacklist:
output = '{} '.format(t)
sheet = '<html><body>' text '</body></html>';
file_object = open("record.html", "w ");
file_object.write(sheet);
file_object.close();
[在此處輸入圖片說明][1] [1]:https://i.stack.imgur.com/sHAMF.png
uj5u.com熱心網友回復:
你可以做這樣的事情,但對于這個網站,我認為最好使用 XPath
import requests
from bs4 import BeautifulSoup
url = 'https://partner.microsoft.com/en-us/membership/application-development-competency'
response = requests.get(url)
soup = BeautifulSoup(response.text, features="lxml")
cols = soup.find_all("div", class_="col-md-4")
print(cols[6].getText())
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/384559.html
