如何解决一个函数中的用户定义输入,而另一个函数Python中不返回任何值
我正在尝试从多个网站获取Contact-Us URL。以下代码不会产生任何错误,但不会产生任何输出。函数find_link产生所需的输出,但是函数contact_check不会产生任何输出。
import xlrd
import os
import re
import requests
import pandas
import sys
from sys import exit
from operator import contains
from bs4 import BeautifulSoup
from bs4.element import Comment
import urllib.request
headers = {'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8',}
def tag_visible(element):
if element.parent.name in ['style','script','head','title','meta','[document]']:
return False
if isinstance(element,Comment):
return False
return True
def find_link(url):
r = requests.get(url,headers = headers)
txt = BeautifulSoup(r.text,'lxml')
links = []
for link in txt.findAll('a'):
links.append(link.get('href'))
return r,links
def contact_check(links):
url1 = ''
match = ['contact','contact us','contact-us','Contact Us','Contact us','Contact','Contact US','contactus','ContactUS','ContactUs']
for link in links:
if (any(b in i for b in match) for i in link):
url1 = link
return url1
text = contact_check(find_link("https://www.genre.com/"))
print(text)
任何帮助将不胜感激! 谢谢!!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。