[问题] 爬虫 卷商分点资料

楼主: unknown (ya)   2022-03-19 09:49:55
爬虫网址:
https://fubon-ebrokerdj.fbs.com.tw/z/zg/zgb/zgb0.djhtm?a=1160&b=1163&c=E&d=1
使用下面语法爬虫 (语法自己摸索可能写的不是很好,也可以指正)
def get_NBA(url):
r = requests.get(url=url)
r.encoding = 'big5'
if r.status_code == requests.codes.ok:
soup = BeautifulSoup(r.text, 'html.parser')
[s.extract() for s in soup("option")]
[s.extract() for s in soup("script")]
[s.extract() for s in soup("SELECT")]
[s.extract() for s in soup("input")]
[s.extract() for s in soup("SCRIPT")]
for tr in soup.find_all('tr'):
for td in tr.findAll('td'):
text = '#'+td.getText()
file.write(text)
file.write('#EENNDD\n')
#file.write('\n')
结果遇到他在主要股号股名那边我就抓不到了
<tr>
<td class="t4t1" nowrap id="oAddCheckbox">
<SCRIPT LANGUAGE=javascript>
<!
作者: wjyo (小废物)   2022-03-19 19:54:00
他股号股名在script元素里面,你前面extract把他排除掉了

Links booklink

Contact Us: admin [ a t ] ucptt.com