此问题与 Chrome DevTools 生成的数据有关。
1. Sign in to your twitter account.
2. Open dev tools, click on the filter icon, type "TweetDetail".
3. Visit the link containing the video or photo: https://twitter.com/StackOverflow/status/1684529654743330817.
4. Right click the link that appears then Copy >> Copy as PowerShell.
5. Add " | select Content | FL" (without quotes) right after -ContentType "application/json" on the last line.
6. Paste the whole code to PowerShell.
结果包含奇怪的代码:
�:Y��(�����?[R:W�8^��9S♣C3▼@�QYd1►��8 jE��і:�B*�☻t�jRY��Ц8+F�z*��
�B��2_�\�
A���2
g�s�ģ�# �}�^�
}�'@�SL]l^1ꕟ��X↨��3▲k���V��,ܤC��2����L→$��↓�☻7����r���4�1aT{��D§K�Ćh�bS(‼u"!RU▲� ∟��Ɂҁ/�B�☺♠B�J"�ȢW��)
�~C�J��eҀ<<�]�▼�@���hgvM|��ږQ��ٶ��������Z♺�t§V���=���
�☺�Klkr�♦���p�azK"3I¶�)��,n�չ]�!�#���y�:��▬�W �'ы1���Yr��"�������ͣ��|∟ma�Y*b�^��MomHݶm(�kG��s�♦���,|<��9д♦�����5�[☺qO�Χ�☺,��)�ȍ���ڃ����O���U�tQ��{��f�
���^�p�ā��!g?.‼�E���j�}�.X�S�
ٙ�9BS�[�fy▬��a�-�D��D��=��W↑�t��↕�QP�Vt�&*�̣j�:�:�►���>4�◄�♦��<��;�4C|�������Z��▼m↔� 9��ߺҁ|�,[����▬�.
����h�^\�ʠQ�w�☻�ڊҺ���s��e��R^�m��b���&����3s�?.G�y��Y_♦����h�7>�m1�.�O��|�v���j��`7♥�w`���
W�m}8���3Ze_� �E↔♦%}y↕b6)t�;��߳�m�‼h+�▼���?f�
..........
如果状态不包含视频或照片,像这个,那么就可以正常读取结果了:
Content : {"data":{"threaded_conversation_with_injections_v2":{"instructions":[{"type":"TimelineAddEntries","entries":[
{"entryId":"tweet-1711788684243046525","sortIndex":"7511583352611729282","content":{"entryType":"TimelineTime
lineItem","__typename":"TimelineTimelineItem","itemContent":{"itemType":"TimelineTweet","__typename":"Timelin
eTweet","tweet_results":{"result":{"__typename":"Tweet","rest_id":"1711788684243046525","has_birdwatch_notes"
:false,
..........
那么,如何确保第一个 URL 的请求结果与第二个 URL 的请求结果相同呢?
注意:在 Linux 终端中Copy as cURL (bash)
,两个链接都会产生正常的字符输出,也就是可读的。
答案1
数据是压缩的,因为你复制的请求里有一句话Accept-Encoding
说你可以接受压缩数据。
我认为 Invoke-WebRequest 不支持这一点,所以最简单的方法可能是通过将标头的值设置为来选择退出"identity"
,始终请求非编码数据。