1
處理this問題的部分答案時,我遇到了一個bs4.element.Tag
,它是嵌套字典和列表(s
,下面)的混亂。在BeautifulSoup中使用字典解析腳本標記
有沒有辦法返回的URL中包含的s
不使用re.find_all
列表?關於這個標籤結構的其他評論也有幫助。
from bs4 import BeautifulSoup
import requests
link = 'https://stackoverflow.com/jobs?med=site-ui&ref=jobs-tab&sort=p'
r = requests.get(link)
soup = BeautifulSoup(r.text, 'html.parser')
s = soup.find('script', type='application/ld+json')
## the first bit of s:
# s
# Out[116]:
# <script type="application/ld+json">
# {"@context":"http://schema.org","@type":"ItemList","numberOfItems":50,
我已經試過:
- 通過與標籤完井方法隨機仔細閱讀上
s
。 - 挑選docs。
我的問題是s
只有1個屬性(type
)和似乎沒有任何子標籤。