if td4.find('万') > -1: td4 = float(td4.replace('万+','')) *10000 td4 = int(td4)
时间: 2024-05-16 11:19:57 浏览: 24
这段代码的作用是将字符串变量`td4`中的数字部分乘以10000,并将结果转换为整型数值。其中,`td4.find('万')`函数返回字符串`td4`中字符`'万'`的索引位置,如果未找到则返回-1。所以,`if td4.find('万') > -1:`的作用是判断`td4`中是否包含字符`'万'`,如果包含则执行下面的两行代码。
第一行代码`td4 = float(td4.replace('万+','')) *10000`将字符串`'万+'`替换为空字符,并将结果转换为浮点数类型,然后乘以10000,最后赋值给变量`td4`。
第二行代码`td4 = int(td4)`将变量`td4`转换为整型数值,并重新赋值给`td4`。这样,`td4`中就存储了乘以10000后的整型数值。
相关问题
if td4.find('万') > -2: td4 = float(td4.replace('万+','')) *10000 td4 = int(td4)是什么意思
这段代码的作用是将字符串变量`td4`中的数字部分乘以10000,并将结果转换为整型数值。其中,`td4.find('万')`函数返回字符串`td4`中字符`'万'`的索引位置,如果未找到则返回-1。所以,`if td4.find('万') > -2:`的作用是判断`td4`中是否包含字符`'万'`,如果包含则执行下面的两行代码。
第一行代码`td4 = float(td4.replace('万+','')) *10000`将字符串`'万+'`替换为空字符,并将结果转换为浮点数类型,然后乘以10000,最后赋值给变量`td4`。
第二行代码`td4 = int(td4)`将变量`td4`转换为整型数值,并重新赋值给`td4`。这样,`td4`中就存储了乘以10000后的整型数值。
import re import urllib from bs4 import BeautifulSoup def weixinData(self, name: str) -> str: # 从此处开始编写代码 curns = 'YES' findname = re.compile(r'<td>(.*?)</td>', re.S) findind = re.compile(r'<span><span.*>(.*?)</span><em>.*</span>') urldate = [] url = "http://72.itmc.org.cn:80/JS001/open/show/weixindata.html" head = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36' } text = urllib.request.Request(url, headers=head) html = '' texts = urllib.request.urlopen(text) html = texts.read().decode('utf-8') shem = BeautifulSoup(html, 'html.parser') for tr in shem.find_all('tr'): tr = str(tr) bate = [] ind = re.findall(findind, tr) bate.append(ind) names = re.findall(findname, tr) bate.append(names) urldate.append(bate) # print(urldate) left, right = 1, (len(urldate)) - 1 # print(right) while left <= right: # print(left) tabe = urldate[left] # print(tabe) # print (tabe[0][0]) if tabe[0][0] == name: # print(4) if tabe[1][2][-1] != '+': # print(1) # print(tabe[1][2]) if float(tabe[1][2]) < 90000: curns = 'NO' if str(tabe[1][5])[-1] != '+': # print(2) if int(tabe[1][5]) < 80000: curns = 'NO' if float(tabe[1][1].replace('万', '')) > 300: # print(3) curns = 'NO' left += 1 return curns print(weixinData('占豪'))
这段代码中的问题在于函数weixinData(self, name: str)的定义中使用了self,但是在函数的调用中没有传递任何参数给self。因此,在调用weixinData()函数时,你需要将类的实例作为第一个参数传递给它。如果你只需要调用这个函数而不是在类中使用它,可以将self从函数定义中删除。此外,你还需要给weixinData()函数传递一个字符串参数name,例如weixinData('占豪')。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)