
主要使用requests库和bs4库中的BeautifulSoup类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
import requests demo = requests.get('http://python123.io/ws/demo.html') from bs4 import BeautifulSoup soup = BeautifulSoup(demo,'html.parser') print(soup.a)
for child in soup.body.children: print(child)
soup.a.parent 返回父亲 soup.a.parents 返回迭代类型
soup.a.next_sibling soup.a.previous_sibling soup.a.next_siblings 迭代类型 soup.a.previous_silblings 迭代类型
print(soup.pretify()) print(soup.a.pretify())
|
XML
JSON
YAML
近期评论