0x01 Install beautifulsoup4 library

pip3 install beautifulsoup4

picture


0x02 Initialization operation

Initialize the string to be manipulated through BeautifulSoup

from bs4 import BeautifulSoupimport requests
url = "https://www.dandanzan10.top/dianying/index.html"heads = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',}r = requests.get(url, headers=heads)str = r.textsp=BeautifulSoup(str,'lxml')print(sp)

0x03 Get the movie name

1. Right-click the string to be obtained and select Inspect Element

picture

2. Pinocchio is under the h2 tag

picture

3. Code implementation

from bs4 import BeautifulSoupimport requestsurl = "https://www.dandanzan10.top/dianying/index.html"heads = {    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',}r = requests.get(url, headers=heads)str = r.textsp=BeautifulSoup(str,'lxml')print(sp.h2.string)


0x04 Get all movie names on this page

from bs4 import BeautifulSoupimport requests
url = "https://www.dandanzan10.top/dianying/index.html"heads = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',}r = requests.get(url, headers=heads)str = r.textsp=BeautifulSoup(str,'lxml')for h2 in sp.find_all(name='h2'): print(h2.string)运行结果: 匹诺曹心弦为君而鸣我的爸爸犬部!孩子不想理解独自生活的人们欧比旺:绝地归来欢快的鬼魂雷神4:爱与雷霆致命邮件:2001 美国炭疽攻击事件布朗克斯大战吸血鬼嚎笑捉鬼队旅馆闹鬼闲山:龙的出现非常宣言鬼影实录:血亲小犬与女孩小鹿乱撞爱上你单向逃离防线-秘密护送爱的透视图坏种2婚头转向海豹自卫队

1. sp.find_all(name='h2'): Get all the contents of the label h2, which is a list

2. Output through the loop

3. Get the string inside through string

0x05 declaration

It is only for safety research and learning. If the tool is used for other purposes, the user shall bear all legal and joint responsibilities, and the author shall not bear any legal and joint responsibilities.

Welcome to the programmers

picture


picture