Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python在标记文本下抓取?_Python_Web Scraping_Beautifulsoup - Fatal编程技术网

Python在标记文本下抓取?

Python在标记文本下抓取?,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我的情况不同,在这种情况下,我想从这类东西中刮取文本,但不知道如何指出它 <td><span class="flag-icon flag-icon-gl"></span>Greenland</td> 格陵兰岛 我不知道如何利用这些员工做一件事。你可以用很多方法来做 使用findspan标记,然后使用parent标记并获取text from bs4 import BeautifulSoup html='''<td>

我的情况不同,在这种情况下,我想从这类东西中刮取文本,但不知道如何指出它

<td><span class="flag-icon flag-icon-gl"></span>Greenland</td>
格陵兰岛
我不知道如何利用这些员工做一件事。

你可以用很多方法来做

使用findspan标记,然后使用parent标记并获取text

from bs4 import BeautifulSoup
html='''<td><span class="flag-icon flag-icon-gl"></span>Greenland</td>'''
soup=BeautifulSoup(html,"html.parser")
print(soup.find("span",class_="flag-icon flag-icon-gl").parent.text)

您需要文本
“格陵兰”
!耶@HumayunAhmadRajib
from bs4 import BeautifulSoup
html='''<td><span class="flag-icon flag-icon-gl"></span>Greenland</td>'''
soup=BeautifulSoup(html,"html.parser")
print(soup.select_one("td>.flag-icon.flag-icon-gl").next_element)