|
@@ -21,28 +21,16 @@ class APILink():
|
|
|
else:
|
|
|
return False
|
|
|
|
|
|
- def fetch_page_source(self,url):
|
|
|
- try:
|
|
|
- response = requests.get(url)
|
|
|
- response.raise_for_status() # 检查请求是否成功
|
|
|
- return response.text # 返回网页源代码
|
|
|
- except requests.RequestException as e:
|
|
|
- print(f"Error fetching the URL: {e}")
|
|
|
- return None
|
|
|
-
|
|
|
- def check_value_in_source(self,url,value):
|
|
|
- page_source = self.fetch_page_source(url)
|
|
|
- if page_source:
|
|
|
- if value in page_source:
|
|
|
- # print(f"'{value_to_check}' exists in the page source.")
|
|
|
- return True
|
|
|
- else:
|
|
|
- # print(f"'{value_to_check}' does not exist in the page source.")
|
|
|
- return False
|
|
|
- else:
|
|
|
- # print("Failed to retrieve the page source.")
|
|
|
- return False
|
|
|
-
|
|
|
+ #打开链接,返回页面底部某个值
|
|
|
+ def obtain_url_bottom(self,url,loc):
|
|
|
+ response = requests.get(url)
|
|
|
+ response.encoding = 'utf-8' # 设置编码为gbk
|
|
|
+ soup = BeautifulSoup(response.text, 'html.parser')
|
|
|
+ # 查找元素并获取值
|
|
|
+ element = soup.find('div', attrs={'class': loc})
|
|
|
+ # element = soup.find(loc)
|
|
|
+ element_value = element.text
|
|
|
+ return element_value
|
|
|
|
|
|
def setup(self):
|
|
|
# 初始化 Playwright
|