re提取不到数据,求大神解答
提取到的关键网页代码:
<tr onclick="location.href='/city/sz.html';" style="cursor: pointer;">
<th>1</th>
<th>
<a href="/city/sz.html" title="深圳房价行情,房价概况走势,数据分析"> 深圳</a>
</th>
<th>74,929</th>
<th class="red">+18.96%</th>
<th class="red">+2.86%</th>
</tr>, <tr onclick="location.href='/city/bj.html';" style="cursor: pointer;">
<th>2</th>
<th>
<a href="/city/bj.html" title="北京房价行情,房价概况走势,数据分析"> 北京</a>
</th>
<th>62,567</th>
<th class="green">-2.09%</th>
<th class="green">-4.76%</th>
</tr>, <tr onclick="location.href='/city/sh.html';" style="cursor: pointer;">
......后边同类型
我的代码:
import requests
from tool import useragenttool
import bs4
import re
import openpyxl
def open_url(url):
"""解析网址,获取源码信息"""
res = requests.get(url, headers=useragenttool.get_headers())
return res
def find_data(res):
datas = []
soup = bs4.BeautifulSoup(res.text, "html.parser")
content = soup.find(class_="gb-dataListBox")
# print(content)
target = content.find_all("tr", style="cursor: pointer;")
# print(target)
target = iter(target)
for each in target:
# print(each.text)
if each.text.isnumeric():
datas.append([
re.search(r'(.+)', next(target).text).group(1),
re.search(r'\d.*', next(target).text).group(),
re.search(r'\d.*', next(target).text).group(),
re.search(r'\d.*', next(target).text).group()])
print(datas)
return datas
def main():
url = "https://www.creprice.cn/rank/cityforsale.html"
res = open_url(url)
datas = find_data(res)
if __name__ == '__main__':
main()
为什么 print(datas)出来的datas列表空的啊,我要爬城市,房价还有后边两个百分数,新手百思不得其解,求大神解答
<tr onclick="location.href='/city/sz.html';" style="cursor: pointer;">
<th>1</th>
<th>
<a href="/city/sz.html" title="深圳房价行情,房价概况走势,数据分析"> 深圳</a>
</th>
<th>74,929</th>
<th class="red">+18.96%</th>
<th class="red">+2.86%</th>
</tr>, <tr onclick="location.href='/city/bj.html';" style="cursor: pointer;">
<th>2</th>
<th>
<a href="/city/bj.html" title="北京房价行情,房价概况走势,数据分析"> 北京</a>
</th>
<th>62,567</th>
<th class="green">-2.09%</th>
<th class="green">-4.76%</th>
</tr>, <tr onclick="location.href='/city/sh.html';" style="cursor: pointer;">
......后边同类型
我的代码:
import requests
from tool import useragenttool
import bs4
import re
import openpyxl
def open_url(url):
"""解析网址,获取源码信息"""
res = requests.get(url, headers=useragenttool.get_headers())
return res
def find_data(res):
datas = []
soup = bs4.BeautifulSoup(res.text, "html.parser")
content = soup.find(class_="gb-dataListBox")
# print(content)
target = content.find_all("tr", style="cursor: pointer;")
# print(target)
target = iter(target)
for each in target:
# print(each.text)
if each.text.isnumeric():
datas.append([
re.search(r'(.+)', next(target).text).group(1),
re.search(r'\d.*', next(target).text).group(),
re.search(r'\d.*', next(target).text).group(),
re.search(r'\d.*', next(target).text).group()])
print(datas)
return datas
def main():
url = "https://www.creprice.cn/rank/cityforsale.html"
res = open_url(url)
datas = find_data(res)
if __name__ == '__main__':
main()
为什么 print(datas)出来的datas列表空的啊,我要爬城市,房价还有后边两个百分数,新手百思不得其解,求大神解答

...全文
相关推荐
rs232转485通信在串口助手只能发送数据而接受不到数据,求大神解答
我是用电脑usb连接rs232然后232两根AB线接到485模块,然后485模块的di和ri连上华大芯片板子的txd,rxd的引脚上,485的re和de连到一起,re随便接到了芯片上的一个引脚上,然后
Python常用模块 之 re:提供整个正则表达式的实现
Python常用模块 之 re:提供整个正则表达式的实现
python中正则表达式 re.findall 用法
如果遇到任何问题,欢迎留言讨论,笔者会尽快回复解答。同时,感谢大家对本站的支持。
数据结构题集解答 数据结构基础题C语言版
"数据结构题集解答 数据结构基础题C语言版"本资源是严蔚敏老师的数据结构C语言版的课后练习题解,非常适合初学者。对提高基础很有帮助。
复变函数与积分变换习题解答
### (5)等式求解已知等式\((3i-5)y + (i+1)x = 3i-5+3\)成立,求实数\(x, y\)的值。


