作者s8607142004 (挖哩勒)
看板Python
标题[问题] Pchome股票网站爬虫
时间Wed Dec 8 22:13:33 2021
各位版上大大好
小弟刚进到爬虫的世界
想尝试爬取Pchome股市的概念股清单
网址如下
https://pchome.megatime.com.tw/group/sto3
先附上程式码
import time
import requests
from bs4 import BeautifulSoup
header={'Referer':'
http://pchome.megatime.com.tw/stock/sto3/',
'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'}
url = "
https://pchome.megatime.com.tw/group/sto3"
r = requests.post(url,header)
r.encoding = 'UTF-8'
sp = BeautifulSoup(r.text, 'html5lib')
sp
在sto3 那个Document里面有看到需要的资料但爬出来的资料却只有下面几行
但爬出来只有看到下面几行
<html><head>
</head>
<body>
<form action="
https://pchome.megatime.com.tw/group/sto3" id="submit_form"
method="post" name="submit_form">
<input name="is_check" type="hidden" value="1"/>
</form>
<script type="text/javascript">
document.getElementById('submit_form').submit();
</script>
</body></html>
有爬到之前的文章说是header设定不对
https://pttdigit.com/python/M.1485354796.A.810.html
但我header 照着这篇大大说的设定方法类比去设还是没办法成功
有另外尝试使用pyppeteer 但也是爬不出来
想请版上大神能指点迷津
感谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 220.135.101.62 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1638972815.A.1BC.html
1F:→ Woqeker: 第一则推文不是有说不能用requests吗 12/10 02:42
2F:→ blc: Referer的意思是 从哪个url来的 不是填你要连的网址 12/10 20:30
3F:→ blc: 抱歉我搞错了 把Referer最後的 / 去掉试试 12/10 20:33
4F:→ s8607142004: 最後是 headers = header 就成功了 12/13 18:07