19
2020
04

import requests and BeautifulSoup

import requests

from bs4 import BeautifulSoup


url = 'https://xxxxxxxxx'

page = requests.get(url)

page.text


soup = BeautifulSoup(page.text, 'html.parser')

print(soup.prettify())


soup.find_all('p')


soup.find_all('p')[2].get_text()


soup.find_all(class_='chorus')


soup.find_all('p', class_='chorus')


soup.find_all(id='third')







e.g.


google_url = 'https://www.google.com.hk'


my_params = {'q': 'yahoo'}

r = requests.get(google_url, params = my_params)


soup = BeautifulSoup(r.text,'html.parser')


items = soup.select('a')

for i in items:

    print("title:\n" + google_url + i.text)

    print("link :\n" + google_url + i.get('href'))


https://ithelp.ithome.com.tw/articles/10186119

« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。