简体   繁体   English

Python:无法解析Javascript呈现的网页

[英]Python: Javascript rendered webpage not parsing

I want to parse the information in the following url . 我想解析以下url中的信息。 I want to parse the Name of the trade, the strategy description and the transactions in the "Trading History" and "Open Positions". 我想在“交易历史”和“未平仓头寸”中解析交易名称,策略描述和交易。 When I parse the page, I do not get this data. 解析页面时,没有得到该数据。 I am new to parsing javascript rendered webpages so I would appreciate some explanation why my code below isn't working. 我是解析javascript呈现的网页的新手,因此,感谢您能解释一下为什么我的以下代码无法正常工作。

import bs4 as bs
import urllib
import dryscrape
import sys
import time

url = 'https://www.zulutrade.com/trader/314062/trading'

sess = dryscrape.Session()
sess.visit(url)
time.sleep(10)
sauce = sess.body()
soup = bs.BeautifulSoup(sauce, 'lxml')

Thanks! 谢谢!

Your link in the code doesn't allow you to get anything cause the original url you should play with is the one I'm pasting below .The one you tried to work with automatically gets redirected to the one I mentioned here. 代码中的链接不允许您获取任何内容,因为您应该使用的原始网址是我在下面粘贴的网址。您尝试使用的网址会自动重定向到我在这里提到的网址。

https://www.zulutrade.com/zulutrade-client/traders/api/providers/314062/tradeHistory?

Scraping json data out of the table from that page is as follows: 从该页面的表中抓取JSON数据如下:

import requests
r = requests.get('https://www.zulutrade.com/zulutrade-client/traders/api/providers/314062/tradeHistory?')
j = r.json()
items = j['content']
for item in items:
    print(item['currency'],item['pips'],item['tradeType'],item['transactionCurrency'],item['id'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM