【发布时间】:2021-11-30 07:12:28
【问题描述】:
我正在尝试获取游戏的标题,但标题我也得到了跨度文本
这是我的代码
import time
import requests,pandas
from bs4 import BeautifulSoup
r = requests.get("https://www.pocketgamer.com/android/best-horror-games/?page=1", headers=
{'User-agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101
Firefox/61.0'})
c = r.content
bs4 = BeautifulSoup(c,"html.parser")
all = bs4.find_all("h3",{"class":"indent"})
print(all)
输出
[<h3 class="indent">
<div><span>1</span></div>
Fran Bow </h3>, <h3 class="indent">
<div><span>2</span></div>
Bendy and the Ink Machine </h3>, <h3 class="indent">
<div><span>3</span></div>
Five Nights at Freddy's </h3>, <h3 class="indent">
<div><span>4</span></div>
Sanitarium </h3>, <h3 class="indent">
<div><span>5</span></div>
OXENFREE </h3>, <h3 class="indent">
<div><span>6</span></div>
Thimbleweed Park </h3>, <h3 class="indent">
<div><span>7</span></div>
Samsara Room </h3>, <h3 class="indent">
我也试过这段代码,但没有用
#all = all.find_all("h3")[0].text
【问题讨论】:
标签: web-scraping beautifulsoup