diff --git a/lxj01.py b/lxj01.py new file mode 100644 index 0000000..af96770 --- /dev/null +++ b/lxj01.py @@ -0,0 +1,13 @@ +from bs4 import BeautifulSoup +import requests +response = requests.get('https://example.com') +html_content = response.text +soup = BeautifulSoup(html_content,'lxml') +title = soup.find('title').string +print("页面标题:",title) +links = soup.find_all('a') +for link in links: + print("链接地址:",link.get('href')) +div_elements = soup.select('div.class_name') +for div in div_elements: + print("div内容:",div.text) \ No newline at end of file