推扬网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
推扬网 门户 你问我答 查看内容

初学者 利用python爬虫网站表格值 显示空值 找不到问题 一起帮忙解决难题,拯救 IT 人 ...

2021-7-22 13:27| 发布者: admin| 查看: 474| 评论: 0|原作者: admin|来自: 推杨站长网

摘要: import requests from bs4 import BeautifulSoup url = 'http://price.naif.org.tw/Query/Query_now.aspx'...
import requests from bs4 import BeautifulSoup url = 'http://price.naif.org.tw/Query/Query_now.aspx' headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) appleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'} resp = requests.get(url, headers=headers) # 设定编码为 utf-8 避免中文乱码问题 resp.encoding = 'utf-8' # 根据 HTTP header 的编码解码後的内容资料(ex. UTF-8),若该网站没设定可能会有中文乱码问题。所以通常会使用 resp.encoding 设定 raw_html = resp.text # 将 HTML 转成 BeautifulSoup 物件 soup = BeautifulSoup(raw_html, 'html.parser') print(soup.select('html > body > #form1 > div.wrap > div.contant > div:nth-child(7) > div > #ContentPlaceHolder_content_GridView_data > tbody > tr:nth-child(4) > td:nth-child(2)'))

上方是我的程式码,
我要爬虫的网站:http://price.naif.org.tw/Query/Query_now.aspx
我要爬虫该表格的值,

但我利用上方的程式码print出来的值显示「[]」空值,
尝试过许多方法结果都一样,
不知道我是不是缺少什麽,
谢谢!


鲜花

握手

雷人

路过

鸡蛋

最新评论

热门推荐
最新资讯

广告服务|投稿要求|禁言标准|版权说明|免责声明|手机版|小黑屋|推扬网 ( 粤ICP备18134897号 )|网站地图 | 邮箱:vayae@hotmail.com

GMT+8, 2024-3-19 13:19 , Processed in 0.062268 second(s), 28 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

返回顶部