Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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
提取包含在带有版权符号©的html标记中的文本;使用Python3_Python_Python 3.x_Web Scraping_Beautifulsoup - Fatal编程技术网

提取包含在带有版权符号©的html标记中的文本;使用Python3

提取包含在带有版权符号©的html标记中的文本;使用Python3,python,python-3.x,web-scraping,beautifulsoup,Python,Python 3.x,Web Scraping,Beautifulsoup,我需要检查网页是否有版权符号©如果有,我提取包含该符号的标签文本。例如,对于网页“profile.theguardian.com/signin”,目标文本为“©2018卫报新闻和媒体有限公司或其附属公司。保留所有权利”。如何使用Python 3.x实现这一点?您好,提交问题时,您应该发布示例代码,但下面应该说明版权标志是否位于特定页面上: from bs4 import BeautifulSoup import urllib.request masterURL = 'https://prof

我需要检查网页是否有版权符号©如果有,我提取包含该符号的标签文本。例如,对于网页“profile.theguardian.com/signin”,目标文本为“©2018卫报新闻和媒体有限公司或其附属公司。保留所有权利”。如何使用Python 3.x实现这一点?

您好,提交问题时,您应该发布示例代码,但下面应该说明版权标志是否位于特定页面上:

from bs4 import BeautifulSoup
import urllib.request


masterURL = 'https://profile.theguardian.com/signin'

sauce = urllib.request.urlopen(masterURL).read()
soup = BeautifulSoup(sauce,'lxml')
temp = soup.prettify().encode('UTF-8')

#\xc2\xa9 is unicode symbol for copyright sign

if(b'\xc2\xa9' in temp):
     print('Copy Right On Page')
else:
     print('No Copy Right on Page')

将其作为
footer\u版权
您可以执行以下操作:

from bs4 import BeautifulSoup
import urllib.request as url
BeautifulSoup(url.urlopen(masterURL).read()).select("p.footer__copyright")

我终于找到了我正在寻找的解决方案

URL = 'https://profile.theguardian.com/signin'
webpage = requests.get(URL)
soup = BeautifulSoup(webpage.content,'html.parser')
symbol = u'\N{COPYRIGHT SIGN}'.encode('utf-8')
symbol = symbol.decode('utf-8')
pattern = r'' + symbol
for tag in soup.findAll(text=re.compile(pattern)):
        copyrightTexts = tag.parent.text
        print(copyrightTexts)

希望这能帮助其他人。感谢您的帮助。

您的解决方案特定于此网页,但版权信息可以放置在不同的标签和属性中。所以我想要一个通用代码,可以使用符号进行搜索。