YouTube2Text

Web scraping: Claude Code for Economists with Paul Goldsmith-Pinkham | Markus Academy | Ep. 162-3 — Transcript

by Markus' Academy · 5,554 words · 859 segments · language en · Watch on YouTube

Full transcript

  1. 0:08Welcome back everybody
  2. 0:11to the mini video series on how to use
  3. 0:13Cloud Code for applied economists with
  4. 0:16Paul Smith Bingham. Hi Paul.
  5. 0:18Hi Marcus, how you doing?
  6. 0:21Now we have the third video. First we
  7. 0:24did installation and terminal setup for
  8. 0:26Cloud Code and Co-work as well.
  9. 0:29And then we talked about data analysis
  10. 0:30with a simple example and today Paul
  11. 0:33will show show us how to scrap
  12. 0:36data from the web.
  13. 0:37And we're looking forward to Paul's
  14. 0:40presentation. [snorts]
  15. 0:42Great. So today we're really going to be
  16. 0:44kind of
  17. 0:45deep in the the woods of doing stuff
  18. 0:48like
  19. 0:49coding and kind of right at the command
  20. 0:51line relative to this. So previously we
  21. 0:53had done some work
  22. 0:55kind of
  23. 0:57really using uh you know, Co-work and
  24. 0:59different things we were talking about
  25. 1:01the the different different things.
  26. 1:03Um
  27. 1:05today we're going to really be focused
  28. 1:07on um
  29. 1:10kind of doing a real data collection
  30. 1:11exercise kind of right at the command
  31. 1:13line just so you can kind of see how
  32. 1:14powerful using Cloud Code is. These are
  33. 1:15things I think that would be doable in
  34. 1:17Cloud Co-work but for today we're going
  35. 1:18to focus really on Cloud um Co-work.
  36. 1:21So
  37. 1:22um
  38. 1:24before we were kind of downloading data
  39. 1:26directly from a government API. So this
  40. 1:29is kind of one of the benefits with
  41. 1:30this, right? Is that it's the data is
  42. 1:32kind of very well structured. We were
  43. 1:33kind of downloading from an API or from
  44. 1:35tables that were already made from
  45. 1:37something that it's meant to be used.
  46. 1:39But a lot of stuff that we're going to
  47. 1:40do, the data isn't really that
  48. 1:41structured at all. So it's you know,
  49. 1:43we're scraping something from the web or
  50. 1:45we're given data that's kind of very
  51. 1:46messy and we're going to do a lot of
  52. 1:48work to turn it into something that is
  53. 1:49structured. So what we're going to do
  54. 1:51today is we're going to use something
  55. 1:53from the SEC the the Securities Exchange
  56. 1:55Commission's uh website which is called
  57. 1:57Edgar. Now, this is still a very
  58. 1:59structured data set, but it's really
  59. 2:00used for regulatory um filings as
  60. 2:03different companies file things. And
  61. 2:06we're going to take what are called
  62. 2:0710-Ks which are annual filings made by
  63. 2:09companies.
  64. 2:10Where we're going to we're going to pull
  65. 2:12stuff out. We're going to build a
  66. 2:13database and then we're going to
  67. 2:14basically do some basic analysis here.
  68. 2:16And we're going to do it all with cloud
  69. 2:18code. So, the example that I want to I
  70. 2:20want to do is is thinking about um
  71. 2:22tariffs.
  72. 2:23So, this is just you know, is I
  73. 2:25something I picked. We could pick lots
  74. 2:27of stories, but I think this would be a
  75. 2:28fun one. So, there in 10-Ks, there is
  76. 2:31something called item 1A which are these
  77. 2:33risk factors which is basically you
  78. 2:35describe material risks that face your
  79. 2:37company. So, when you have new risks,
  80. 2:39you have to talk about it. So, there's
  81. 2:41no quantity per se described in it. But,
  82. 2:43one thing that's interesting to measure
  83. 2:45is sort of how much these tariff risks
  84. 2:47change and came up and how often is this
  85. 2:49being described as a material risk over
  86. 2:51time for these folks.
  87. 2:53Um you know, this is a lot of related to
  88. 2:55a lot of work about uh this is the work
  89. 2:57by Baker, Bloom, and Davis thinking
  90. 2:59about policy uncertainty and macro. And
  91. 3:01it's just risk factors generally is is
  92. 3:03really interesting kind of
  93. 3:05if you're interested in this type of
  94. 3:06problem, there's no reason to focus per
  95. 3:08se on tariffs, but pulling this data can
  96. 3:09be kind of a pain. I'm going to show you
  97. 3:11it's really
  98. 3:12kind of a straightforward problem. So,
  99. 3:15we're going to do a number of things,
  100. 3:17but it's all going to kind of be we're
  101. 3:18not going to have to do too much. You
  102. 3:20mainly Marcus and I will be sitting here
  103. 3:21watching what's going on and talking
  104. 3:23about it. We're going to scrape 10-K
  105. 3:25filings from Edgar. We're going to
  106. 3:26extract the information from item 1A.
  107. 3:28We're going to put this into a database
  108. 3:30and then we're going to query that
  109. 3:32database to talk about various trends
  110. 3:34that are used in that. And maybe we'll
  111. 3:35make a picture that kind of looks nice
  112. 3:37um to describe this.
  113. 3:39So, I'm going to just show you what this
  114. 3:41looks like and then I'm about to move
  115. 3:43over to the command line in a second,
  116. 3:44but I'm going to kind of really give a
  117. 3:45structured prompt um for this just to
  118. 3:48make life easy. Um
  119. 3:51I'm going to ask I'm going to say I want
  120. 3:52to build a database a data set of 10K
  121. 3:55risk factors
  122. 3:56um from SEC SEC Edgar to study how
  123. 3:59tariff related risk disclosure change
  124. 4:01from this time period. We could change
  125. 4:02that if you wanted. Here's what I need
  126. 4:04to know or here's what I want to know
  127. 4:06from Edgar. Every company here or here's
  128. 4:09what I know about it, excuse me. Every
  129. 4:10company has a CIK, which is just means
  130. 4:12that there's a If you have a company,
  131. 4:15you have a number in Edgar that's
  132. 4:16associated with you.
  133. 4:18Here is where the API is.
  134. 4:21So
  135. 4:22for this one, I'm going to give Claude a
  136. 4:24little more context up front than usual.
  137. 4:26So, you know, I'm going to actually tell
  138. 4:29it a little more explicitly the things
  139. 4:30that I know. I'm not going to be so
  140. 4:31quite as vague as I was in the last
  141. 4:33prompt, mainly to make life easier for
  142. 4:34it. If you remember from the first
  143. 4:36video, I talked about is kind of the the
  144. 4:38how well it does as a function of how
  145. 4:40clear and precise you are. So, the more
  146. 4:43precise I am, the less it can have to
  147. 4:44search randomly for things. I'm going to
  148. 4:46say, "Look, I want to build a data set
  149. 4:47of 10K risk factors
  150. 4:50to study how tariff related risk
  151. 4:51disclosure change. Here's what I know.
  152. 4:54So, I know how it's structured. You have
  153. 4:56to have a CIK. You need Here's the um
  154. 4:59Edgar filing API and here's how you
  155. 5:01should rate limit it. And you need to
  156. 5:02use something called the user agent
  157. 5:03header, which is a way, if you remember
  158. 5:05from the last video, that this is to
  159. 5:07keep it from basically so it can clear
  160. 5:10these websites.
  161. 5:11And I want 10Ks What's the rate limit?
  162. 5:14Sorry.
  163. 5:15Oh, the rate limit is so that it doesn't
  164. 5:16just try and get too many files from
  165. 5:18this. So, I'm saying I see. You can only
  166. 5:20download, you know, 10 every second
  167. 5:22here. So, it's it's to keep you from
  168. 5:25spamming the server and getting blocked.
  169. 5:27And most of the time
  170. 5:29uh Claude would know beforehand, but
  171. 5:31this is
  172. 5:32This is roughly the rate that you can
  173. 5:33>> And the user agent, that's
  174. 5:35Yes, that's just a way to um to tell
  175. 5:37This is a way to tell the Python script
  176. 5:39that it writes to pretend they basically
  177. 5:42have to have a user agent associated
  178. 5:43with it, which is going to be my name
  179. 5:44and my email address. Okay. Um you're
  180. 5:47going to say, I want and I'm going to do
  181. 5:48it for 30 firms in different things. I'm
  182. 5:51going to just give it some examples.
  183. 5:52Obviously, if we're doing this for a
  184. 5:53research project, we'd say do it for
  185. 5:55every, you know, publicly listed stock,
  186. 5:56you know, all 500 and maybe I give it a
  187. 5:58list of names. But for here, I'm just
  188. 6:00going to let Claude make some decisions.
  189. 6:02Okay. So, I'm going to do this now. I'm
  190. 6:03going to take this over. So, I'm going
  191. 6:04to pause for 1 second as I move over and
  192. 6:06do this on the command line.
  193. 6:08Great. So, here we are at the command
  194. 6:10line, Marcus. So, what we're going to do
  195. 6:11is I'm going to make a a folder that
  196. 6:13this is inside of the one of the things
  197. 6:15that I've been doing. It's I'm just
  198. 6:16called a
  199. 6:17I'm just going to make a folder that
  200. 6:18we'll go in. We're going to start a new
  201. 6:20fresh Claude
  202. 6:22um session.
  203. 6:24And
  204. 6:25here, I'm going to tell it to basically
  205. 6:28create um I'm going to give it the
  206. 6:30prompt that we just talked about. So,
  207. 6:31we're going to start the project. So,
  208. 6:32I'm going to put it in. It's going to
  209. 6:34have this pasted text and I'm going to
  210. 6:36say I want to build a data set, blah
  211. 6:37blah blah. It's everything we just
  212. 6:38talked about. Mhm. So, it's going to
  213. 6:39start thinking and it's going to say,
  214. 6:40"Okay, I'm going to enter plan mode."
  215. 6:43So, now it's saying, "Okay, I need to
  216. 6:44make a plan on how to do this." So, let
  217. 6:46me think about how to do this.
  218. 6:48"Okay, it's going to look here."
  219. 6:51Um
  220. 6:52it's thinking. And so, one thing you can
  221. 6:54do is you can look
  222. 6:57and it's saying it it ran a command. It
  223. 6:59said this is called LS, which means it
  224. 7:01looks inside. It says, "Hey, this is a
  225. 7:02brand new folder. There's nothing in
  226. 7:04here." Yeah. So, it's thinking. So, you
  227. 7:06remember how we talked about how there's
  228. 7:07a context window where it does lots of
  229. 7:08stuff. So, now it says, "Wants to build
  230. 7:10a thing that does this. This is a
  231. 7:11project a substantial project that
  232. 7:13involves all these things. It's a
  233. 7:14non-trivial implementation. Let me enter
  234. 7:16plan mode to design the approach before
  235. 7:18doing this."
  236. 7:20Now, it's saying, "Okay, let me look at
  237. 7:22this and research the Edgar API before
  238. 7:24designing it." I'm going to say, "Yes,
  239. 7:25you can fetch this content from here."
  240. 7:26I'm going to say, "Yes, and don't ask
  241. 7:28again."
  242. 7:29"Yes, and don't ask again." I'm giving
  243. 7:31it lots of permissions to go search
  244. 7:32things on the web. And here's how you
  245. 7:34can search. It's looking up for
  246. 7:35documentation. So, right now it's
  247. 7:37running all of these commands, which is
  248. 7:39looking for it's asking, you know, what
  249. 7:42are things here? What goes What's going
  250. 7:44on here? So, it's doing a lot of
  251. 7:45different tool commands all at the same
  252. 7:47time.
  253. 7:48Um and it's trying to figure out how to
  254. 7:50query Edgar
  255. 7:53um
  256. 7:54to do different things. So, I'm giving
  257. 7:56it a lot of permissions just so it can
  258. 7:57go and search and understand how to do
  259. 7:58this.
  260. 7:59This is a bit like what you and I would
  261. 8:01do if we were going and looking this up.
  262. 8:02It just reads faster than I do.
  263. 8:05Um
  264. 8:06So, it's working. It's working. It's
  265. 8:08working.
  266. 8:09Once it's kind of figured out how these
  267. 8:10tools work, it's going to then try to
  268. 8:12make a plan.
  269. 8:14So, it's figuring out, okay, well,
  270. 8:15here's the the different filing things.
  271. 8:17Here's what it's doing.
  272. 8:19>> [snorts]
  273. 8:20>> And so, it's it's searching. Still
  274. 8:22searching. You can see it's kind of
  275. 8:23refining what it's going on. And so,
  276. 8:24what the way to think about these is
  277. 8:26that
  278. 8:27these are each tools that it goes and
  279. 8:29does something and then it sends
  280. 8:30something back to the to the agent. And
  281. 8:33we actually don't see it in this window,
  282. 8:34but that's what it's doing. Now, it's
  283. 8:36it's trying to pull something from this
  284. 8:38person's GitHub page. I'm going to say
  285. 8:39yes. You can go look at that.
  286. 8:41But it's still making a plan, no?
  287. 8:44Okay, great. So,
  288. 8:45we had to stop really quick there,
  289. 8:47Marcus. Sorry about that. But one thing
  290. 8:48that's great about this is I interrupted
  291. 8:50while I was in the middle of this and
  292. 8:51that can happen for a number of reasons.
  293. 8:52Maybe you you kind of hit the button by
  294. 8:55accident cuz you have fat fingers or or
  295. 8:57you maybe your computer turns off or
  296. 9:00something like this. The amazing thing
  297. 9:02is cuz of we talked about how the
  298. 9:03context window works, you see it says
  299. 9:05interrupted, you know, what should
  300. 9:07Claude do instead cuz I hit escape. I
  301. 9:09can say, "Well, oh, please continue."
  302. 9:13So, it just says, "Oh, well, I'll just
  303. 9:14keep working then."
  304. 9:15So, I can just say this. It's going to
  305. 9:17say, "Okay, well, I'll just keep
  306. 9:18working. Let me research some more."
  307. 9:20>> it?
  308. 9:21So, I interrupted it when I when we uh
  309. 9:24Okay.
  310. 9:24>> So, it, you know, it's saying, "Oh, we
  311. 9:25have these errors." It's going to
  312. 9:27continue planning. Let's keep going. So,
  313. 9:29obviously there were some errors here
  314. 9:31that that occurred. It's going to keep
  315. 9:32working. It needs a user agent. So, I
  316. 9:35know the API well.
  317. 9:37So, it's going to do this. Let me
  318. 9:38clarify a few things before we do it.
  319. 9:40So, it It tried to do this and so now
  320. 9:42this is the coolest part of this. So,
  321. 9:43this is what one thing that's really
  322. 9:45lovely about Claude Code is it's It's
  323. 9:47going to ask me questions about how I
  324. 9:48want to do it. Remember when we did
  325. 9:49Claude Co-work, it did the same thing.
  326. 9:51Yeah. How do you want this structured?
  327. 9:53And so, do you want a SQL-like database?
  328. 9:56So, with things? Do you want a flat
  329. 9:58file? Do you want both?
  330. 10:00I'm actually going to tell it I want
  331. 10:01something called DuckDB,
  332. 10:03um which is very similar to a SQL-like
  333. 10:05database. It's just how I prefer to do
  334. 10:07things. Um
  335. 10:08So, you This is a fourth option. You can
  336. 10:10say DuckDB database,
  337. 10:12um please.
  338. 10:13Uh remember I'm very polite. So,
  339. 10:17then you could say, "Do you want a
  340. 10:18keyword search? Um extract the full text
  341. 10:20and then flag paragraphs?
  342. 10:22You want to extract the full section and
  343. 10:24do the keyword analysis later? Or do you
  344. 10:27want to do LLM classification, but then
  345. 10:29I would have to pay for it?" I'm going
  346. 10:30to do the keyword search. We're just
  347. 10:31going to look for words that are related
  348. 10:33to tariffs.
  349. 10:35Um
  350. 10:36and I And says, "What entity should we
  351. 10:38use for the user agent?" Remember you
  352. 10:40have to give this header. It's saying,
  353. 10:41"Do you want to fill it in later? Or do
  354. 10:43you want to do it right now?" I'm going
  355. 10:44to say I'm going to do it right now.
  356. 10:45I'll provide it.
  357. 10:47And then
  358. 10:49it's going to ask me. It's going to say,
  359. 10:50"Okay, well, please write your thing in
  360. 10:52now."
  361. 10:53And so, you know, you asked this before
  362. 10:55is that the planning takes a while. It's
  363. 10:57kind of similar to you'd say,
  364. 10:59um
  365. 11:00So, what name and So, So, what it's
  366. 11:02going to say is
  367. 11:03I It's saying, "Oh, it's very kind of
  368. 11:05interesting." It's saying, "Use
  369. 11:06placeholder text for now. I'll type it."
  370. 11:08And it's saying,
  371. 11:09"Write it here in number three." So,
  372. 11:11when it says, "I'll type it," it's
  373. 11:12saying, "Please put it here." So, I'll
  374. 11:14say, "My name is Paul Goldsmith Bingham.
  375. 11:16My email is [email protected]."
  376. 11:20So, I did that.
  377. 11:22And it's going to do this. So, it's
  378. 11:23going to put this here.
  379. 11:25And what we were talking about planning,
  380. 11:26what's really is kind of remarkable is
  381. 11:29with many projects, the plan is almost
  382. 11:31just as important as the execution. I
  383. 11:34see. Because sort of similar to like
  384. 11:37kind of when we do research, often what
  385. 11:39we're doing is trying to figure out what
  386. 11:41the plan is, right? Like we're just sort
  387. 11:42of saying we have a vague idea, let's
  388. 11:45iterate. When you work in a software
  389. 11:47engineer kind of setting, much of what
  390. 11:49you're doing is related to that. So,
  391. 11:50it's thinking really hard. You see how
  392. 11:52it if we went into here, it says, "Let
  393. 11:54me design this. I've all the info we
  394. 11:56need. Here's what we're going to do.
  395. 11:57Here's implement it. Here's my plan. I'm
  396. 11:59going to do this. It's going to do these
  397. 12:00targets."
  398. 12:02Um duck DB schema.
  399. 12:05Here are words I'm going to look for.
  400. 12:06Here's all these words. Now, I'm
  401. 12:08thinking through the target list I
  402. 12:10should do. If I'd given it a list, it
  403. 12:11would have been easier for it. So,
  404. 12:13retail, tech. Now, I need to figure out
  405. 12:16how to do this.
  406. 12:17I'm also thinking about what whether to
  407. 12:19use the API or just download the
  408. 12:21complete thing is better.
  409. 12:23So, I'm going to access the filing index
  410. 12:25through this, use beautiful soup, which
  411. 12:26is just a package to parse the HTML, and
  412. 12:28then look for something in the text.
  413. 12:30But, if I wanted to change something now
  414. 12:32as in oh, there was something wrong with
  415. 12:34Yeah, that's a great question. Yeah, so
  416. 12:35Yeah, so add another firm or something?
  417. 12:38Great. So, yeah, yeah. So, here's what
  418. 12:39we're going to do. So, here's the plan
  419. 12:41summary. So, we now have a plan, it
  420. 12:43says. Okay.
  421. 12:44>> So, remember how we talked about when
  422. 12:46there was this managed context window we
  423. 12:47were saying how it's useful to be in
  424. 12:49charge of it, like you do research, and
  425. 12:50then you can This is what we talked
  426. 12:52about in the first video.
  427. 12:53You would write down a plan. So, Claude
  428. 12:55has now kind of automated this directly.
  429. 12:57They're actually just plans I see.
  430. 12:59>> in here, and what it does in plan mode
  431. 13:00is it constructs a file, which is kind
  432. 13:02of the compressed memory of all the
  433. 13:04planning it did into an executable idea.
  434. 13:07Okay. So, here it's saying, "Here's the
  435. 13:09plan summary. I'm going to make a script
  436. 13:10that does looks for the CIKs for all of
  437. 13:12these.
  438. 13:14Then going to find them here. It's going
  439. 13:16to get all their filings, and I'm going
  440. 13:18to filter for 10-Ks. I'm going to
  441. 13:20download and parse each 10-K and look
  442. 13:22for item 1A. Mhm.
  443. 13:24>> I'm going to look for certain words, and
  444. 13:25then I'm going to store this in a
  445. 13:26database.
  446. 13:28And what it's going to do is it's going
  447. 13:29to cache the data, which means that
  448. 13:31after it's downloaded the HTML, it won't
  449. 13:33download it again. Remember we talked
  450. 13:34about this last time it was
  451. 13:35re-downloading things, which felt slow?
  452. 13:38This is a good example of it's just
  453. 13:39going to download all the raw data into
  454. 13:41a place so that it doesn't get stuck
  455. 13:44re-downloading every time.
  456. 13:46And then it's going to give lots of
  457. 13:47details what the plan is cuz this is the
  458. 13:48basically it's instructions to itself.
  459. 13:51So, it's going to say, "All right, I'm
  460. 13:52going to build a pipeline that does
  461. 13:53this.
  462. 13:54Here's the target companies, so it's
  463. 13:56going to be three different kinds.
  464. 13:58Here's the architecture. Here's how
  465. 14:00you're going to do it. This is just the
  466. 14:01longer version of what I described
  467. 14:02above.
  468. 14:03But that's where the one of the keywords
  469. 14:05I would like to instead of tariffs, I
  470. 14:07want to
  471. 14:08Yeah, you want to say you want to add
  472. 14:10another one. You want to say like "What
  473. 14:12if we added in Trump as well?" Like
  474. 14:14Trump or Yeah, so totally. So, we could
  475. 14:17say
  476. 14:18"Do you want it This is the plan. Would
  477. 14:19you like to do it?" And so, you could
  478. 14:21say yes, clear context, and auto accept.
  479. 14:23So, what that means is Mhm. Get Remember
  480. 14:26how you wipe the window and you just
  481. 14:27read the plan and go? One is you could
  482. 14:29say just yes, I'm going to I don't I I
  483. 14:31don't want to wipe it. I just want to go
  484. 14:32from here.
  485. 14:34Or yes, but I don't want to just auto
  486. 14:36accept what you're going to do. I see.
  487. 14:38Or four, what I'm going to say is
  488. 14:40"Please add in references to Liberation
  489. 14:44Day. Perhaps Liberation
  490. 14:45>> The Liberation Day. Great idea. Yes.
  491. 14:50Um to the tariff
  492. 14:52keywords.
  493. 14:57So, I It's going to say here, "Tool use
  494. 14:58rejected with this message. Please add
  495. 15:00in this." And it's thinking, "Good call.
  496. 15:02Liberation Day is very positive." Claude
  497. 15:04is always a very positive. With April
  498. 15:052nd, 2025 tariff now, let me update the
  499. 15:08keywords. So, add Liberation Day and
  500. 15:10Liberation Day tariff to the keyword
  501. 15:12list. And so, it's going to do that and
  502. 15:14it will put it here. Liberation Day,
  503. 15:15Liberation Day tariff.
  504. 15:17And everything else is pretty similar.
  505. 15:19It would be weird. So,
  506. 15:21for the interest of this, so I'm going
  507. 15:22to kind of
  508. 15:24um I'm going to say yes. I'm going to
  509. 15:25say go ahead and auto accept edits. So,
  510. 15:27that's going to let it write everything
  511. 15:29and do thing It won't be able to execute
  512. 15:30things, but it will be able to write and
  513. 15:32edit files on its own. So, but now it
  514. 15:35the
  515. 15:35you compress this everything, the old
  516. 15:37stuff, no?
  517. 15:39Yes, it will get rid of all the planning
  518. 15:40it did before when it clears the context
  519. 15:42window. That's side of what it's saying
  520. 15:44is it's going to clear all the old
  521. 15:45stuff, but it's going to save this plan
  522. 15:46that we just read through into a file.
  523. 15:48In fact, you can see it right here.
  524. 15:51Um it's going to edit It's going to have
  525. 15:53this plan right here as a file that it
  526. 15:55saves it. It actually keeps track of all
  527. 15:56your files, these these plans. And so,
  528. 15:59it says here I could actually
  529. 16:01>> this three meek knitting I call Yeah, so
  530. 16:03it just has The way that it does this is
  531. 16:05that it just combines three now three
  532. 16:07different words together. So, it's an
  533. 16:09adverb, noun, and noun.
  534. 16:11Um
  535. 16:12Um so,
  536. 16:15I'm going to say yes.
  537. 16:16Clear context and accept and accept
  538. 16:18edits.
  539. 16:20So, now it has this in here. Um
  540. 16:23and
  541. 16:25um
  542. 16:29Um and so, now it's running. So, it's
  543. 16:32going to write some information here.
  544. 16:34Um Thinking again essentially, but it
  545. 16:37had a plan already.
  546. 16:38>> Yeah, but the thinking The thinking is
  547. 16:39just that it's thinking about how to
  548. 16:40actually implement the plan. Now, it has
  549. 16:42It has a plan It has It knows how it
  550. 16:44wants to do it. Okay.
  551. 16:46>> Um
  552. 16:47It's And we can look at how it's
  553. 16:48thinking. It wants me to implement this.
  554. 16:50Let me create the files,
  555. 16:51requirements.txt. That's just for the
  556. 16:53packages, and then How did you switch on
  557. 16:56the thinking to looking into the
  558. 16:57thinking?
  559. 16:59Oh, thinking is just a word that it's
  560. 17:00using. So, it's like smooshing or
  561. 17:02anything. This is just random verb or
  562. 17:04>> if you want to look into the thinking
  563. 17:05process Oh, I'm sorry. Great question.
  564. 17:07Yes, I should have said this. So, if you
  565. 17:09hit control O, it will show the what's
  566. 17:11thinking. And if you hit control O
  567. 17:13again, it will go back. That's my I
  568. 17:15should have said that. Yeah.
  569. 17:16>> What does the O stand for? Just as a I
  570. 17:19think just open probably is the easiest
  571. 17:21way to think of that. Like it opens up
  572. 17:23all the stuff that's going on behind the
  573. 17:24scenes.
  574. 17:25>> I see. Um so here I just wrote a bunch
  575. 17:27of code. It wrote 480 so it just wrote
  576. 17:29all this script here. It's a Python
  577. 17:31script that just wrote all of this. You
  578. 17:33know, it has all the phases that we
  579. 17:35talked about. So here's phase one that
  580. 17:37does the look up. Mhm. It has all I mean
  581. 17:39this is all code that would take a
  582. 17:40little while to write yourself and did
  583. 17:42it, you know, in just a minute or two.
  584. 17:44>> to be able to double-check this code or
  585. 17:45you just run with it?
  586. 17:47I mean it's sort of the benefit is that
  587. 17:48if it if you have a way of knowing that
  588. 17:50it worked correctly, that's helpful. So
  589. 17:52you should know that it's going to pull
  590. 17:54uh you know, three five three to four
  591. 17:56filings for 30 companies. So you should
  592. 17:58know you should have 128 five like rows
  593. 18:01of filing information. Okay.
  594. 18:03>> And so that's one way to know. So now
  595. 18:05it's going to just do Now it's going to
  596. 18:06try and run stuff. So here it's
  597. 18:07installing dependencies. Mhm. Um
  598. 18:13And so I it's going to say, "Hey, you
  599. 18:14already have these things so you don't
  600. 18:16need it." So I didn't need to install
  601. 18:17anything new and that's going to run
  602. 18:18this scraper.
  603. 18:20It will take several minutes since it
  604. 18:21downloads 90 plus filings. I don't know
  605. 18:23if that's true.
  606. 18:25Um so it could not find something. So
  607. 18:29it's actually running here in the
  608. 18:30background. This is
  609. 18:32Um could not find the CIK for this
  610. 18:34company.
  611. 18:35I see.
  612. 18:36>> Now it's downloading here. So it did a
  613. 18:38bunch very quickly. Here's a 30. It just
  614. 18:41It's looking for the filings. Mhm.
  615. 18:44And it's gotten most of those. So this
  616. 18:46is figuring out where all the filings
  617. 18:48are and now it's downloading the actual
  618. 18:49documents.
  619. 18:51So this is actually this is
  620. 18:53coming from its own command line that
  621. 18:55it's running. It's running this
  622. 18:56It downloader here. It's downloading and
  623. 18:58extracting information. So it We're
  624. 19:00missing it for a few I think we're
  625. 19:02missing it for one company.
  626. 19:04So it has all but one and so it's
  627. 19:07running here. Now we're up to 22 26%.
  628. 19:11It's downloading. Can I ask get laid on
  629. 19:13which company the CIK stands for which
  630. 19:15company?
  631. 19:17Oh, this GPA the one that it missed?
  632. 19:19Yes. Yeah. Um,
  633. 19:20we can So, one thing that's nice is you
  634. 19:22can queue your um questions. You could
  635. 19:25say, "What company was it unable to find
  636. 19:29a CIK for?" Okay. And so, and then you
  637. 19:32could you can edit it if you if you
  638. 19:34change your mind, you can press up to
  639. 19:36edit it. Um Okay.
  640. 19:40Oops, sorry.
  641. 19:43And so, that will answer it. So, we're
  642. 19:45almost done, 93%. And so, what's nice is
  643. 19:47you could go and um look at the folder
  644. 19:50really quick. Um
  645. 19:52So, if we go and look in the folder
  646. 19:55um well, I guess I won't do this cuz I
  647. 19:57don't want to
  648. 19:58It's what I can tell you is it's
  649. 19:59downloaded 116 of these already. So, it
  650. 20:02it did it. It's running this command and
  651. 20:04it's it's here.
  652. 20:06Um the pipeline ran successfully. Here's
  653. 20:08the summary.
  654. 20:10It did 29 out of 30. Do you So,
  655. 20:15And GPS is Gap Inc. It's the one ticker
  656. 20:18it couldn't find a CIK for. That's
  657. 20:19because GA Gap Inc. rebranded and it's
  658. 20:21now traded under Gap in some data sets.
  659. 20:23So, we can look If you would like, I can
  660. 20:26look up the correct ticker mapping and
  661. 20:27add it. Yes, please add it.
  662. 20:31Okay.
  663. 20:32So, now we'll see what it does in
  664. 20:33response to this question.
  665. 20:36Um
  666. 20:39And it will go and it will look. So,
  667. 20:41what it's doing is it's looking in the
  668. 20:42SEC Edgar
  669. 20:44and the company tickers of where Gap is.
  670. 20:48Um
  671. 20:50So, I'm giving it permission to do this.
  672. 20:54And
  673. 20:56See if I can Pretty cool.
  674. 20:59Yeah. So, it's searching. It's trying to
  675. 21:01figure out what its CIK is. It looks
  676. 21:02like it's done.
  677. 21:04Um
  678. 21:05CIK 39911 Let's see Let's me check why I
  679. 21:09did. Was it case sensitivity or
  680. 21:11something else?
  681. 21:14And it looks like it was because it was
  682. 21:15GAAP.
  683. 21:17Mhm. Not GPS. And so I'll update the
  684. 21:19script to use GAAP instead. And so it's
  685. 21:22going to change it in here to be
  686. 21:23correct. Now let me rerun. Since it's
  687. 21:25cached, it's only going to download one
  688. 21:27file. Okay. Okay.
  689. 21:29So it should be very quick. Yes, it's
  690. 21:30cached.
  691. 21:32Only four new files. It was about 43
  692. 21:34seconds. The cache files are written
  693. 21:35here. Da da da. Okay. So now it only So
  694. 21:39now we can ask the next question which
  695. 21:40it said, "Okay, well we only got 112 out
  696. 21:43of the 120 sections extracted Mhm. with
  697. 21:46113 tariff paragraphs. So
  698. 21:49um why didn't we get 120 item
  699. 21:54uh one paragraphs?
  700. 21:57So it seemed like we are missing a few
  701. 22:00without these.
  702. 22:01Um good call. Eight filings failed the
  703. 22:04item 1A extraction.
  704. 22:06So let me check which ones. It's going
  705. 22:08to check. Looks like it's from several
  706. 22:10of these ones that um are Honeywell and
  707. 22:13Intel. Every filing for both the regex
  708. 22:16must not be matching what they're doing.
  709. 22:18So there's an element to which if you
  710. 22:19know it's mandatory to have these one
  711. 22:21check is to say, "Hey, every year there
  712. 22:23should be an an item for this." Yeah. So
  713. 22:26figure out what's going on.
  714. 22:28And so it's writing this code. I'm, you
  715. 22:30know, the joke with these LM things is
  716. 22:31often you just hit enter. You don't even
  717. 22:33look at the code every time because
  718. 22:34there's so many things it's going to
  719. 22:35check. Um but obviously, you know,
  720. 22:38So in both of these, item 1A and risk
  721. 22:41factor are on separate lines with a new
  722. 22:42line between them. The current regex
  723. 22:44requires them to be on the same line.
  724. 22:45The fix is to allow new lines.
  725. 22:47Uh it's going to do some work here to
  726. 22:49fix this. Regex, if you're not familiar,
  727. 22:51is just a way to look for patterns in
  728. 22:52string. Now it's going to rerun it. So
  729. 22:55um after you're done with this, instead
  730. 22:59of trying to
  731. 23:01fix these two, can you show how uh uh um
  732. 23:06how much uh which
  733. 23:10firms are most um
  734. 23:12mentioning
  735. 23:14um tariffs with
  736. 23:17Uh you always Can you show the show is
  737. 23:19missing?
  738. 23:22Oh, yes. Thank you. It probably wouldn't
  739. 23:24even care. Can you it would say it would
  740. 23:27probably make its best guess.
  741. 23:29Okay. Let's see how it did. Big
  742. 23:31improvement. 119.
  743. 23:33So, it's going to keep trying to do
  744. 23:35this. It's still trying to figure it
  745. 23:36out.
  746. 23:37But,
  747. 23:38it's just 3M now.
  748. 23:40He's managed to break 3M.
  749. 23:43So, it's going to say it's likely in a
  750. 23:44filing formatting edge case.
  751. 23:46Mhm.
  752. 23:46>> 10K might have unusual structure. Yada
  753. 23:48yada yada.
  754. 23:50Um let's proceed. I'm going to ask it to
  755. 23:52do this thing. It's going to look and
  756. 23:54it's going to say
  757. 23:55what's the top word So, it's going to
  758. 23:57give me some information. Mhm.
  759. 23:59It wrote a script to do this. And so,
  760. 24:01what here's what it'll do. So, I said
  761. 24:03um which firms mention tariffs the most?
  762. 24:07The ones that mention it the most are
  763. 24:09manufacturing. So,
  764. 24:10um
  765. 24:11Deere John Deere leads with the most
  766. 24:13tariff mentions increasing from three to
  767. 24:15four over time.
  768. 24:16Manufacturing tech hardware retail firms
  769. 24:18mention it the the least.
  770. 24:21They both jumped to three.
  771. 24:22It AVGO dropped from four to zero. Mhm.
  772. 24:26And Walmart's only started mentioning
  773. 24:27tariffs in 2025. Oh, yeah. So, most
  774. 24:30paragraphs have it.
  775. 24:33So, it's it shows up more. So, the
  776. 24:34question is is please download the 10Ks
  777. 24:40for um 2010
  778. 24:43um for these same firms and identify
  779. 24:48um
  780. 24:49the um um
  781. 24:51um identify the tariff
  782. 24:54measures there as well.
  783. 24:57It looks like even in 2010 it mentions
  784. 25:00it. Mhm.
  785. 25:01Um so, we're going to sort of see even
  786. 25:04in 2010, you know, 18 companies mention
  787. 25:07it. Okay.
  788. 25:09So, it looks like, you know,
  789. 25:12it was already widespread here, but the
  790. 25:14intensity has increased. More paragraphs
  791. 25:15per company in previous years. Not sure
  792. 25:18if that's So, 25 across 18 versus 26 to
  793. 25:2135 per year in in roughly the same
  794. 25:24number.
  795. 25:25In 2010 it was narrower, mainly tariff,
  796. 25:27trade restrictions, anti-dumping,
  797. 25:28countervailing. Now it's, you know,
  798. 25:30trade tension, trade dispute, trade war.
  799. 25:33I see. Um
  800. 25:35and so on. So, you know, you could do a
  801. 25:37lot more with this. It's sort of
  802. 25:38interesting. I don't think something
  803. 25:39that I was aware of of kind of how
  804. 25:41common it is. I think the next thing if
  805. 25:42I was going to do this, which we could
  806. 25:44do some other time or
  807. 25:45you, the viewer, can do is you could do
  808. 25:48this for a lot more firms. I mean, I
  809. 25:49think the biggest difference that's
  810. 25:50happened here, right, is that in this
  811. 25:52time period there's just far more um
  812. 25:55things going on. It's hitting a lot more
  813. 25:57firms and so understanding the
  814. 25:59cross-section of firms here would be
  815. 26:00very interesting. Right.
  816. 26:02>> So, um hopefully this is interesting. I
  817. 26:05think one of the things that you're
  818. 26:06interested in thinking about macro risks
  819. 26:08and doing this, parsing this kind of
  820. 26:10data, the cost I mean, we did this in
  821. 26:12about 30 minutes
  822. 26:13is way lower and you could start
  823. 26:15thinking about other risk factors and
  824. 26:16other things to do. It doesn't require a
  825. 26:18team of RAs or anything else and
  826. 26:19hopefully, you know, this could be
  827. 26:21useful for you going forward in the
  828. 26:22future.
  829. 26:23Fantastic.
  830. 26:25All right.
  831. 26:29Great.
  832. 26:30So,
  833. 26:32I think with that, I think we'll wrap
  834. 26:34up, Marcus, unless you have anything
  835. 26:35else you wanted to add. I think just to
  836. 26:37summarize, we basically we did and ended
  837. 26:41up taking um a little bit more than our
  838. 26:43usual time, but we we basically
  839. 26:46worked with this LLM to kind of cons-
  840. 26:49ask a question of Edgar, which is a the
  841. 26:52Securities and Exchange Commission's
  842. 26:54website. We downloaded a bunch of
  843. 26:56basically raw filing data and asked
  844. 26:58Claude to write parsing scripts for us.
  845. 27:01It put it into structured database and
  846. 27:03then we were able to ask questions in a
  847. 27:05pretty quick amount of time. So, next
  848. 27:07time we're going to think about much
  849. 27:08bigger data sets and how to structure
  850. 27:10them and I'm looking forward to joining
  851. 27:12them.
  852. 27:13That is good. Thanks a lot, Paul, and
  853. 27:15thanks for all of you for following and
  854. 27:18be excited about the next mini video
  855. 27:21um
  856. 27:23coming up soon.
  857. 27:24Cheers.
  858. 27:25>> Great. Bye-bye.
  859. 27:26>> Cheers. Bye-bye.

About this transcript

This page contains the full transcript of Web scraping: Claude Code for Economists with Paul Goldsmith-Pinkham | Markus Academy | Ep. 162-3 by Markus' Academy, generated from the public captions YouTube serves with the video. The transcript has 5,554 words across 859 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.