On 16Nov2015 15:41, Crusier <crus...@gmail.com> wrote:
I am currently trying to download the stock code. I am using Python
3.4 and the code is as follows:
[...]
   for link in soup.find_all("a"):
       stock_code = re.search('/d/d/d/d/d', "00001" )
       print(stock_code, '', link.text)
[...]
I am trying to retrieve the stock code from here:
<td class="verd_black12" width="18%">00001</td>
or from a href.

Well it looks like you have all the needed libraries. You're doing a few things wrong above. Firstly, to match a digit you need "\d", not "/d". Secondly, your use of "re.search" searches the literal string "00001" instead of, presumably, the value of link.text. Thirdly, the return from "re.search" is not a stock code but a "match object"; I would not call it "stock_code" but "stock_code_match". That will contain a reference to the stock code; since your regexp matches the stock code then stock_code_match.group(0) will return the actual matched text, the stock code.

Fix that stuff and see where you are.

Cheers,
Cameron Simpson <c...@zip.com.au>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to